mirror of
https://github.com/golang/go
synced 2024-11-25 07:07:57 -07:00
http: permit empty Reason-Phrase in response Status-Line
Fixes #1388. R=rsc CC=golang-dev https://golang.org/cl/3749043
This commit is contained in:
parent
4a7d1f2061
commit
d71d08af5a
@ -86,10 +86,14 @@ func ReadResponse(r *bufio.Reader, requestMethod string) (resp *Response, err os
|
||||
return nil, err
|
||||
}
|
||||
f := strings.Split(line, " ", 3)
|
||||
if len(f) < 3 {
|
||||
if len(f) < 2 {
|
||||
return nil, &badStringError{"malformed HTTP response", line}
|
||||
}
|
||||
resp.Status = f[1] + " " + f[2]
|
||||
reasonPhrase := ""
|
||||
if len(f) > 2 {
|
||||
reasonPhrase = f[2]
|
||||
}
|
||||
resp.Status = f[1] + " " + reasonPhrase
|
||||
resp.StatusCode, err = strconv.Atoi(f[1])
|
||||
if err != nil {
|
||||
return nil, &badStringError{"malformed HTTP status code", f[1]}
|
||||
|
@ -122,6 +122,44 @@ var respTests = []respTest{
|
||||
|
||||
"Body here\n",
|
||||
},
|
||||
|
||||
// Status line without a Reason-Phrase, but trailing space.
|
||||
// (permitted by RFC 2616)
|
||||
{
|
||||
"HTTP/1.0 303 \r\n\r\n",
|
||||
Response{
|
||||
Status: "303 ",
|
||||
StatusCode: 303,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
RequestMethod: "GET",
|
||||
Header: map[string]string{},
|
||||
Close: true,
|
||||
ContentLength: -1,
|
||||
},
|
||||
|
||||
"",
|
||||
},
|
||||
|
||||
// Status line without a Reason-Phrase, and no trailing space.
|
||||
// (not permitted by RFC 2616, but we'll accept it anyway)
|
||||
{
|
||||
"HTTP/1.0 303\r\n\r\n",
|
||||
Response{
|
||||
Status: "303 ",
|
||||
StatusCode: 303,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
RequestMethod: "GET",
|
||||
Header: map[string]string{},
|
||||
Close: true,
|
||||
ContentLength: -1,
|
||||
},
|
||||
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
func TestReadResponse(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user