1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 type respWriteTest struct {
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 for i := range respWriteTests {
96 tt := &respWriteTests[i]
98 err := tt.Resp.Write(&braw)
100 t.Errorf("error writing #%d: %s", i, err)
103 sraw := braw.String()
105 t.Errorf("Test %d, expecting:\n%q\nGot:\n%q\n", i, tt.Raw, sraw)