Commit bdb2f976 authored by Evan Kroske's avatar Evan Kroske Committed by Brad Fitzpatrick

net/http: correct error message for incorrect Body length

Fixes #8140.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/131900044
parent 3e9c7a8a
...@@ -280,7 +280,7 @@ var reqWriteTests = []reqWriteTest{ ...@@ -280,7 +280,7 @@ var reqWriteTests = []reqWriteTest{
ContentLength: 10, // but we're going to send only 5 bytes ContentLength: 10, // but we're going to send only 5 bytes
}, },
Body: []byte("12345"), Body: []byte("12345"),
WantError: errors.New("http: Request.ContentLength=10 with Body length 5"), WantError: errors.New("http: ContentLength=10 with Body length 5"),
}, },
// Request with a ContentLength of 4 but an 8 byte body. // Request with a ContentLength of 4 but an 8 byte body.
...@@ -294,7 +294,7 @@ var reqWriteTests = []reqWriteTest{ ...@@ -294,7 +294,7 @@ var reqWriteTests = []reqWriteTest{
ContentLength: 4, // but we're going to try to send 8 bytes ContentLength: 4, // but we're going to try to send 8 bytes
}, },
Body: []byte("12345678"), Body: []byte("12345678"),
WantError: errors.New("http: Request.ContentLength=4 with Body length 8"), WantError: errors.New("http: ContentLength=4 with Body length 8"),
}, },
// Request with a 5 ContentLength and nil body. // Request with a 5 ContentLength and nil body.
......
...@@ -228,7 +228,7 @@ func (t *transferWriter) WriteBody(w io.Writer) error { ...@@ -228,7 +228,7 @@ func (t *transferWriter) WriteBody(w io.Writer) error {
} }
if !t.ResponseToHEAD && t.ContentLength != -1 && t.ContentLength != ncopy { if !t.ResponseToHEAD && t.ContentLength != -1 && t.ContentLength != ncopy {
return fmt.Errorf("http: Request.ContentLength=%d with Body length %d", return fmt.Errorf("http: ContentLength=%d with Body length %d",
t.ContentLength, ncopy) t.ContentLength, ncopy)
} }
......
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