1
0
mirror of https://github.com/golang/go synced 2024-11-12 10:30:23 -07:00

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

Fixes #6564

R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/52420043
This commit is contained in:
Brad Fitzpatrick 2014-01-14 19:08:40 -08:00
parent 0db71338ed
commit 89c9d6b7f8
2 changed files with 12 additions and 0 deletions

View File

@ -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)

View File

@ -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{}