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 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 func TestResponseWrite(t *testing.T) {
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)