diff options
Diffstat (limited to 'src/pkg/http/responsewrite_test.go')
-rw-r--r-- | src/pkg/http/responsewrite_test.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/pkg/http/responsewrite_test.go b/src/pkg/http/responsewrite_test.go index 228ed5f7d..de0635da5 100644 --- a/src/pkg/http/responsewrite_test.go +++ b/src/pkg/http/responsewrite_test.go @@ -6,6 +6,7 @@ package http import ( "bytes" + "io/ioutil" "testing" ) @@ -23,7 +24,7 @@ var respWriteTests = []respWriteTest{ ProtoMinor: 0, RequestMethod: "GET", Header: Header{}, - Body: nopCloser{bytes.NewBufferString("abcdef")}, + Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")), ContentLength: 6, }, @@ -39,7 +40,7 @@ var respWriteTests = []respWriteTest{ ProtoMinor: 0, RequestMethod: "GET", Header: Header{}, - Body: nopCloser{bytes.NewBufferString("abcdef")}, + Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")), ContentLength: -1, }, "HTTP/1.0 200 OK\r\n" + @@ -54,7 +55,7 @@ var respWriteTests = []respWriteTest{ ProtoMinor: 1, RequestMethod: "GET", Header: Header{}, - Body: nopCloser{bytes.NewBufferString("abcdef")}, + Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")), ContentLength: 6, TransferEncoding: []string{"chunked"}, Close: true, @@ -65,6 +66,29 @@ var respWriteTests = []respWriteTest{ "Transfer-Encoding: chunked\r\n\r\n" + "6\r\nabcdef\r\n0\r\n\r\n", }, + + // Header value with a newline character (Issue 914). + // Also tests removal of leading and trailing whitespace. + { + Response{ + StatusCode: 204, + ProtoMajor: 1, + ProtoMinor: 1, + RequestMethod: "GET", + Header: Header{ + "Foo": []string{" Bar\nBaz "}, + }, + Body: nil, + ContentLength: 0, + TransferEncoding: []string{"chunked"}, + Close: true, + }, + + "HTTP/1.1 204 No Content\r\n" + + "Connection: close\r\n" + + "Foo: Bar Baz\r\n" + + "\r\n", + }, } func TestResponseWrite(t *testing.T) { @@ -78,7 +102,7 @@ func TestResponseWrite(t *testing.T) { } sraw := braw.String() if sraw != tt.Raw { - t.Errorf("Test %d, expecting:\n%s\nGot:\n%s\n", i, tt.Raw, sraw) + t.Errorf("Test %d, expecting:\n%q\nGot:\n%q\n", i, tt.Raw, sraw) continue } } |