OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Tests for client.go | 5 // Tests for client.go |
6 | 6 |
7 package http_test | 7 package http_test |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 } | 1029 } |
1030 want := Header{ | 1030 want := Header{ |
1031 "Server-Trailer-A": []string{"valuea"}, | 1031 "Server-Trailer-A": []string{"valuea"}, |
1032 "Server-Trailer-B": nil, | 1032 "Server-Trailer-B": nil, |
1033 "Server-Trailer-C": []string{"valuec"}, | 1033 "Server-Trailer-C": []string{"valuec"}, |
1034 } | 1034 } |
1035 if !reflect.DeepEqual(res.Trailer, want) { | 1035 if !reflect.DeepEqual(res.Trailer, want) { |
1036 t.Errorf("Response trailers = %#v; want %#v", res.Trailer, want) | 1036 t.Errorf("Response trailers = %#v; want %#v", res.Trailer, want) |
1037 } | 1037 } |
1038 } | 1038 } |
| 1039 |
| 1040 func TestReferer(t *testing.T) { |
| 1041 tests := []struct { |
| 1042 lastReq, newReq string // from -> to URLs |
| 1043 want string |
| 1044 }{ |
| 1045 // don't send user: |
| 1046 {"http://gopher@test.com", "http://link.com", "http://test.com"}
, |
| 1047 {"https://gopher@test.com", "https://link.com", "https://test.co
m"}, |
| 1048 |
| 1049 // don't send a user and password: |
| 1050 {"http://gopher:go@test.com", "http://link.com", "http://test.co
m"}, |
| 1051 {"https://gopher:go@test.com", "https://link.com", "https://test
.com"}, |
| 1052 |
| 1053 // nothing to do: |
| 1054 {"http://test.com", "http://link.com", "http://test.com"}, |
| 1055 {"https://test.com", "https://link.com", "https://test.com"}, |
| 1056 |
| 1057 // https to http doesn't send a referer: |
| 1058 {"https://test.com", "http://link.com", ""}, |
| 1059 {"https://gopher:go@test.com", "http://link.com", ""}, |
| 1060 } |
| 1061 for _, tt := range tests { |
| 1062 l, err := url.Parse(tt.lastReq) |
| 1063 if err != nil { |
| 1064 t.Fatal(err) |
| 1065 } |
| 1066 n, err := url.Parse(tt.newReq) |
| 1067 if err != nil { |
| 1068 t.Fatal(err) |
| 1069 } |
| 1070 r := ExportRefererForURL(l, n) |
| 1071 if r != tt.want { |
| 1072 t.Errorf("refererForURL(%q, %q) = %q; want %q", tt.lastR
eq, tt.newReq, r, tt.want) |
| 1073 } |
| 1074 } |
| 1075 } |
OLD | NEW |