mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: omit invalid header value from error message
Updates #43631
Change-Id: I0fe3aafdf7ef889fed1a830128721393f8d020e6
GitHub-Last-Rev: c359542d74
GitHub-Pull-Request: golang/go#48979
Reviewed-on: https://go-review.googlesource.com/c/go/+/355929
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
4a2a3bca18
commit
e822b1e26e
2 changed files with 10 additions and 9 deletions
|
|
@ -525,7 +525,8 @@ func (t *Transport) roundTrip(req *Request) (*Response, error) {
|
||||||
for _, v := range vv {
|
for _, v := range vv {
|
||||||
if !httpguts.ValidHeaderFieldValue(v) {
|
if !httpguts.ValidHeaderFieldValue(v) {
|
||||||
req.closeBody()
|
req.closeBody()
|
||||||
return nil, fmt.Errorf("net/http: invalid header field value %q for key %v", v, k)
|
// Don't include the value in the error, because it may be sensitive.
|
||||||
|
return nil, fmt.Errorf("net/http: invalid header field value for %q", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6085,14 +6085,14 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
Method: " ",
|
Method: " ",
|
||||||
URL: u,
|
URL: u,
|
||||||
},
|
},
|
||||||
wantErr: "invalid method",
|
wantErr: `invalid method " "`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nil URL",
|
name: "nil URL",
|
||||||
req: &Request{
|
req: &Request{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
},
|
},
|
||||||
wantErr: "nil Request.URL",
|
wantErr: `nil Request.URL`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid header key",
|
name: "invalid header key",
|
||||||
|
|
@ -6101,7 +6101,7 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
Header: Header{"💡": {"emoji"}},
|
Header: Header{"💡": {"emoji"}},
|
||||||
URL: u,
|
URL: u,
|
||||||
},
|
},
|
||||||
wantErr: "invalid header field name",
|
wantErr: `invalid header field name "💡"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid header value",
|
name: "invalid header value",
|
||||||
|
|
@ -6110,7 +6110,7 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
Header: Header{"key": {"\x19"}},
|
Header: Header{"key": {"\x19"}},
|
||||||
URL: u,
|
URL: u,
|
||||||
},
|
},
|
||||||
wantErr: "invalid header field value",
|
wantErr: `invalid header field value for "key"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "non HTTP(s) scheme",
|
name: "non HTTP(s) scheme",
|
||||||
|
|
@ -6118,7 +6118,7 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
URL: &url.URL{Scheme: "faux"},
|
URL: &url.URL{Scheme: "faux"},
|
||||||
},
|
},
|
||||||
wantErr: "unsupported protocol scheme",
|
wantErr: `unsupported protocol scheme "faux"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no Host in URL",
|
name: "no Host in URL",
|
||||||
|
|
@ -6126,7 +6126,7 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
URL: &url.URL{Scheme: "http"},
|
URL: &url.URL{Scheme: "http"},
|
||||||
},
|
},
|
||||||
wantErr: "no Host",
|
wantErr: `no Host in request URL`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6142,8 +6142,8 @@ func TestTransportClosesBodyOnInvalidRequests(t *testing.T) {
|
||||||
if !bc {
|
if !bc {
|
||||||
t.Fatal("Expected body to have been closed")
|
t.Fatal("Expected body to have been closed")
|
||||||
}
|
}
|
||||||
if g, w := err.Error(), tt.wantErr; !strings.Contains(g, w) {
|
if g, w := err.Error(), tt.wantErr; !strings.HasSuffix(g, w) {
|
||||||
t.Fatalf("Error mismatch\n\t%q\ndoes not contain\n\t%q", g, w)
|
t.Fatalf("Error mismatch: %q does not end with %q", g, w)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue