mirror of https://github.com/golang/go.git
net/http: return nicer error when Client request Host is blank
Update #4271 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6931052
This commit is contained in:
parent
be5ce4e027
commit
f85b94aa85
|
|
@ -144,6 +144,9 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) {
|
|||
}
|
||||
return rt.RoundTrip(req)
|
||||
}
|
||||
if req.URL.Host == "" {
|
||||
return nil, errors.New("http: no Host in request URL")
|
||||
}
|
||||
treq := &transportRequest{Request: req}
|
||||
cm, err := t.connectMethodForRequest(treq)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1062,6 +1062,20 @@ func TestTransportAltProto(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTransportNoHost(t *testing.T) {
|
||||
tr := &Transport{}
|
||||
_, err := tr.RoundTrip(&Request{
|
||||
Header: make(Header),
|
||||
URL: &url.URL{
|
||||
Scheme: "http",
|
||||
},
|
||||
})
|
||||
want := "http: no Host in request URL"
|
||||
if got := fmt.Sprint(err); got != want {
|
||||
t.Errorf("error = %v; want %q", err, want)
|
||||
}
|
||||
}
|
||||
|
||||
var proxyFromEnvTests = []struct {
|
||||
env string
|
||||
wanturl string
|
||||
|
|
|
|||
Loading…
Reference in New Issue