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:
parent
0db71338ed
commit
89c9d6b7f8
@ -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{}
|
||||
|
Loading…
Reference in New Issue
Block a user