Commit f85b94aa authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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
parent be5ce4e0
......@@ -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
......
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