18
var respWriteTests = []respWriteTest{
19
// HTTP/1.0, identity coding; no trailer
25
Request: dummyReq("GET"),
27
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
31
"HTTP/1.0 503 Service Unavailable\r\n" +
32
"Content-Length: 6\r\n\r\n" +
35
// Unchunked response without Content-Length.
41
Request: dummyReq("GET"),
43
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
46
"HTTP/1.0 200 OK\r\n" +
50
// HTTP/1.1, chunked coding; empty trailer; close
56
Request: dummyReq("GET"),
58
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
60
TransferEncoding: []string{"chunked"},
64
"HTTP/1.1 200 OK\r\n" +
65
"Connection: close\r\n" +
66
"Transfer-Encoding: chunked\r\n\r\n" +
67
"6\r\nabcdef\r\n0\r\n\r\n",
70
// Header value with a newline character (Issue 914).
71
// Also tests removal of leading and trailing whitespace.
77
Request: dummyReq("GET"),
79
"Foo": []string{" Bar\nBaz "},
83
TransferEncoding: []string{"chunked"},
87
"HTTP/1.1 204 No Content\r\n" +
88
"Connection: close\r\n" +
94
18
func TestResponseWrite(t *testing.T) {
19
respWriteTests := []respWriteTest{
20
// HTTP/1.0, identity coding; no trailer
26
Request: dummyReq("GET"),
28
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
32
"HTTP/1.0 503 Service Unavailable\r\n" +
33
"Content-Length: 6\r\n\r\n" +
36
// Unchunked response without Content-Length.
42
Request: dummyReq("GET"),
44
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
47
"HTTP/1.0 200 OK\r\n" +
51
// HTTP/1.1, chunked coding; empty trailer; close
57
Request: dummyReq("GET"),
59
Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
61
TransferEncoding: []string{"chunked"},
65
"HTTP/1.1 200 OK\r\n" +
66
"Connection: close\r\n" +
67
"Transfer-Encoding: chunked\r\n\r\n" +
68
"6\r\nabcdef\r\n0\r\n\r\n",
71
// Header value with a newline character (Issue 914).
72
// Also tests removal of leading and trailing whitespace.
78
Request: dummyReq("GET"),
80
"Foo": []string{" Bar\nBaz "},
84
TransferEncoding: []string{"chunked"},
88
"HTTP/1.1 204 No Content\r\n" +
89
"Connection: close\r\n" +
95
95
for i := range respWriteTests {
96
96
tt := &respWriteTests[i]
97
97
var braw bytes.Buffer