noTrailer,
noError,
},
+
+ // leading whitespace in the first header. golang.org/issue/22464
+ {
+ "GET / HTTP/1.1\r\n Foobar: ignored\r\nConnection: close\r\n\r\n",
+ &Request{
+ Method: "GET",
+ URL: &url.URL{
+ Path: "/",
+ },
+ Header: Header{"Connection": {"close"}},
+ Proto: "HTTP/1.1",
+ ProtoMajor: 1,
+ ProtoMinor: 1,
+ RequestURI: "/",
+ Close: true,
+ },
+ noBodyStr,
+ noTrailer,
+ noError,
+ },
}
func TestReadRequest(t *testing.T) {
},
"Your Authentication failed.\r\n",
},
+
+ // leading whitespace in the first header. golang.org/issue/22464
+ {
+ "HTTP/1.1 200 OK\r\n" +
+ " Content-type: text/html\r\n" +
+ "\tIgnore: foobar\r\n" +
+ "Foo: bar\r\n\r\n",
+ Response{
+ Status: "200 OK",
+ StatusCode: 200,
+ Proto: "HTTP/1.1",
+ ProtoMajor: 1,
+ ProtoMinor: 1,
+ Request: dummyReq("GET"),
+ Header: Header{
+ "Foo": {"bar"},
+ },
+ Close: true,
+ ContentLength: -1,
+ },
+ "",
+ },
}
// tests successful calls to ReadResponse, and inspects the returned Response.
}
m := make(MIMEHeader, hint)
+
+ for r.skipSpace() > 0 {
+ line, err := r.readLineSlice()
+ if len(line) == 0 || err != nil {
+ return m, err
+ }
+ }
+
for {
kv, err := r.readContinuedLineSlice()
if len(kv) == 0 {
}
}
+func TestReadMIMEHeaderLeadingSpace(t *testing.T) {
+ tests := []struct {
+ input string
+ want MIMEHeader
+ }{
+ {" Ignore: ignore\r\nFoo: foo\r\n\r\n", MIMEHeader{"Foo": {"foo"}}},
+ {"\tIgnore: ignore\r\nFoo: foo\r\n\r\n", MIMEHeader{"Foo": {"foo"}}},
+ {" Ignore1: ignore\r\n Ignore2: ignore\r\nFoo: foo\r\n\r\n", MIMEHeader{"Foo": {"foo"}}},
+ {" Ignore1: ignore\r\n\r\n", MIMEHeader{}},
+ }
+ for _, tt := range tests {
+ r := reader(tt.input)
+ m, err := r.ReadMIMEHeader()
+ if !reflect.DeepEqual(m, tt.want) || err != nil {
+ t.Errorf("ReadMIMEHeader(%q) = %v, %v; want %v", tt.input, m, err, tt.want)
+ }
+ }
+}
+
// Test that continued lines are properly trimmed. Issue 11204.
func TestReadMIMEHeaderTrimContinued(t *testing.T) {
// In this header, \n and \r\n terminated lines are mixed on purpose.