net/textproto: ignore initial lines with leading whitespaces in ReadMIMEHeader

A header line with leading whitespaces is not valid in HTTP as per
RFC7230. This change ignores these invalid lines in ReadMIMEHeader.

Updates #22464

Change-Id: Iff9f00380d28a9617a55ff7888a76fba82001402
Reviewed-on: https://go-review.googlesource.com/75350
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Wèi Cōngruì 2017-11-02 14:23:32 +08:00 committed by Brad Fitzpatrick
parent 17f35c6993
commit 5d0cab0367
4 changed files with 69 additions and 0 deletions

View file

@ -555,6 +555,28 @@ some body`,
},
"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.