Commit 89c9d6b7 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: return UnexpectedEOF instead of EOF on truncated resposne

Fixes #6564

R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/52420043
parent 0db71338
......@@ -141,6 +141,9 @@ func ReadResponse(r *bufio.Reader, req *Request) (*Response, error) {
// Parse the response headers.
mimeHeader, err := tp.ReadMIMEHeader()
if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return nil, err
}
resp.Header = Header(mimeHeader)
......
......@@ -618,6 +618,15 @@ func TestResponseContentLengthShortBody(t *testing.T) {
}
}
func TestReadResponseUnexpectedEOF(t *testing.T) {
br := bufio.NewReader(strings.NewReader("HTTP/1.1 301 Moved Permanently\r\n" +
"Location: http://example.com"))
_, err := ReadResponse(br, nil)
if err != io.ErrUnexpectedEOF {
t.Errorf("ReadResponse = %v; want io.ErrUnexpectedEOF", err)
}
}
func TestNeedsSniff(t *testing.T) {
// needsSniff returns true with an empty response.
r := &response{}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment