OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 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 package http | 5 package http |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "fmt" | 10 "fmt" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 var respTests = []respTest{ | 22 var respTests = []respTest{ |
23 // Unchunked response without Content-Length. | 23 // Unchunked response without Content-Length. |
24 respTest{ | 24 respTest{ |
25 "HTTP/1.0 200 OK\r\n" + | 25 "HTTP/1.0 200 OK\r\n" + |
26 "Connection: close\r\n" + | 26 "Connection: close\r\n" + |
27 "\r\n" + | 27 "\r\n" + |
28 "Body here\n", | 28 "Body here\n", |
29 | 29 |
30 Response{ | 30 Response{ |
31 » » » Status: "200 OK", | 31 » » » Status: "200 OK", |
32 » » » StatusCode: 200, | 32 » » » StatusCode: 200, |
33 » » » Proto: "HTTP/1.0", | 33 » » » Proto: "HTTP/1.0", |
34 » » » ProtoMajor: 1, | 34 » » » ProtoMajor: 1, |
35 » » » ProtoMinor: 0, | 35 » » » ProtoMinor: 0, |
36 RequestMethod: "GET", | 36 RequestMethod: "GET", |
37 Header: map[string]string{ | 37 Header: map[string]string{ |
38 "Connection": "close", // TODO(rsc): Delete? | 38 "Connection": "close", // TODO(rsc): Delete? |
39 }, | 39 }, |
40 » » » Close: true, | 40 » » » Close: true, |
41 ContentLength: -1, | 41 ContentLength: -1, |
42 }, | 42 }, |
43 | 43 |
44 "Body here\n", | 44 "Body here\n", |
45 }, | 45 }, |
46 | 46 |
47 // Unchunked response with Content-Length. | 47 // Unchunked response with Content-Length. |
48 respTest{ | 48 respTest{ |
49 "HTTP/1.0 200 OK\r\n" + | 49 "HTTP/1.0 200 OK\r\n" + |
50 "Content-Length: 10\r\n" + | 50 "Content-Length: 10\r\n" + |
51 "Connection: close\r\n" + | 51 "Connection: close\r\n" + |
52 "\r\n" + | 52 "\r\n" + |
53 "Body here\n", | 53 "Body here\n", |
54 | 54 |
55 Response{ | 55 Response{ |
56 » » » Status: "200 OK", | 56 » » » Status: "200 OK", |
57 » » » StatusCode: 200, | 57 » » » StatusCode: 200, |
58 » » » Proto: "HTTP/1.0", | 58 » » » Proto: "HTTP/1.0", |
59 » » » ProtoMajor: 1, | 59 » » » ProtoMajor: 1, |
60 » » » ProtoMinor: 0, | 60 » » » ProtoMinor: 0, |
61 RequestMethod: "GET", | 61 RequestMethod: "GET", |
62 Header: map[string]string{ | 62 Header: map[string]string{ |
63 » » » » "Connection": "close", // TODO(rsc): Delete? | 63 » » » » "Connection": "close", // TODO(rsc): Delete? |
64 » » » » "Content-Length": "10", // TODO(rsc): Delete? | 64 » » » » "Content-Length": "10", // TODO(rsc): Delete? |
65 }, | 65 }, |
66 » » » Close: true, | 66 » » » Close: true, |
67 ContentLength: 10, | 67 ContentLength: 10, |
68 }, | 68 }, |
69 | 69 |
70 "Body here\n", | 70 "Body here\n", |
71 }, | 71 }, |
72 | 72 |
73 // Chunked response without Content-Length. | 73 // Chunked response without Content-Length. |
74 respTest{ | 74 respTest{ |
75 "HTTP/1.0 200 OK\r\n" + | 75 "HTTP/1.0 200 OK\r\n" + |
76 "Transfer-Encoding: chunked\r\n" + | 76 "Transfer-Encoding: chunked\r\n" + |
77 "\r\n" + | 77 "\r\n" + |
78 "0a\r\n" + | 78 "0a\r\n" + |
79 "Body here\n" + | 79 "Body here\n" + |
80 "0\r\n" + | 80 "0\r\n" + |
81 "\r\n", | 81 "\r\n", |
82 | 82 |
83 Response{ | 83 Response{ |
84 » » » Status: "200 OK", | 84 » » » Status: "200 OK", |
85 » » » StatusCode: 200, | 85 » » » StatusCode: 200, |
86 » » » Proto: "HTTP/1.0", | 86 » » » Proto: "HTTP/1.0", |
87 » » » ProtoMajor: 1, | 87 » » » ProtoMajor: 1, |
88 » » » ProtoMinor: 0, | 88 » » » ProtoMinor: 0, |
89 » » » RequestMethod: "GET", | 89 » » » RequestMethod: "GET", |
90 » » » Header: map[string]string{}, | 90 » » » Header: map[string]string{}, |
91 » » » Close: true, | 91 » » » Close: true, |
92 » » » ContentLength: -1, | 92 » » » ContentLength: -1, |
93 TransferEncoding: []string{"chunked"}, | 93 TransferEncoding: []string{"chunked"}, |
94 }, | 94 }, |
95 | 95 |
96 "Body here\n", | 96 "Body here\n", |
97 }, | 97 }, |
98 | 98 |
99 // Chunked response with Content-Length. | 99 // Chunked response with Content-Length. |
100 respTest{ | 100 respTest{ |
101 "HTTP/1.0 200 OK\r\n" + | 101 "HTTP/1.0 200 OK\r\n" + |
102 "Transfer-Encoding: chunked\r\n" + | 102 "Transfer-Encoding: chunked\r\n" + |
103 "Content-Length: 10\r\n" + | 103 "Content-Length: 10\r\n" + |
104 "\r\n" + | 104 "\r\n" + |
105 "0a\r\n" + | 105 "0a\r\n" + |
106 "Body here\n" + | 106 "Body here\n" + |
107 "0\r\n" + | 107 "0\r\n" + |
108 "\r\n", | 108 "\r\n", |
109 | 109 |
110 Response{ | 110 Response{ |
111 » » » Status: "200 OK", | 111 » » » Status: "200 OK", |
112 » » » StatusCode: 200, | 112 » » » StatusCode: 200, |
113 » » » Proto: "HTTP/1.0", | 113 » » » Proto: "HTTP/1.0", |
114 » » » ProtoMajor: 1, | 114 » » » ProtoMajor: 1, |
115 » » » ProtoMinor: 0, | 115 » » » ProtoMinor: 0, |
116 » » » RequestMethod: "GET", | 116 » » » RequestMethod: "GET", |
117 » » » Header: map[string]string{}, | 117 » » » Header: map[string]string{}, |
118 » » » Close: true, | 118 » » » Close: true, |
119 » » » ContentLength: -1, // TODO(rsc): Fix? | 119 » » » ContentLength: -1, // TODO(rsc): Fix? |
120 TransferEncoding: []string{"chunked"}, | 120 TransferEncoding: []string{"chunked"}, |
121 }, | 121 }, |
122 | 122 |
123 "Body here\n", | 123 "Body here\n", |
124 }, | 124 }, |
125 } | 125 } |
126 | 126 |
127 func TestReadResponse(t *testing.T) { | 127 func TestReadResponse(t *testing.T) { |
128 for i := range respTests { | 128 for i := range respTests { |
129 tt := &respTests[i] | 129 tt := &respTests[i] |
(...skipping 26 matching lines...) Expand all Loading... |
156 t.Errorf("%s: type mismatch %v vs %v", prefix, hv.Type(), wv.Typ
e()) | 156 t.Errorf("%s: type mismatch %v vs %v", prefix, hv.Type(), wv.Typ
e()) |
157 } | 157 } |
158 for i := 0; i < hv.NumField(); i++ { | 158 for i := 0; i < hv.NumField(); i++ { |
159 hf := hv.Field(i).Interface() | 159 hf := hv.Field(i).Interface() |
160 wf := wv.Field(i).Interface() | 160 wf := wv.Field(i).Interface() |
161 if !reflect.DeepEqual(hf, wf) { | 161 if !reflect.DeepEqual(hf, wf) { |
162 t.Errorf("%s: %s = %v want %v", prefix, hv.Type().(*refl
ect.StructType).Field(i).Name, hf, wf) | 162 t.Errorf("%s: %s = %v want %v", prefix, hv.Type().(*refl
ect.StructType).Field(i).Name, hf, wf) |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
OLD | NEW |