Skip to content

Commit

Permalink
net/http: expose "http: server gave HTTP response to HTTPS client" error
Browse files Browse the repository at this point in the history
Expose "http: server gave HTTP response to HTTPS client" error as
ErrSchemeMismatch, so that it can be compared with errors.Is .

Fixes golang#44855

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Jan 31, 2022
1 parent eab9a77 commit 00c8e88
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/net/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func (c *Client) transport() RoundTripper {
return DefaultTransport
}

// ErrSchemeMismatch is returned when server gave HTTP response to HTTPS client.
var ErrSchemeMismatch = errors.New("http: server gave HTTP response to HTTPS client")

// send issues an HTTP request.
// Caller should close resp.Body when done reading from it.
func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, didTimeout func() bool, err error) {
Expand Down Expand Up @@ -260,7 +263,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, d
// response looks like HTTP and give a more helpful error.
// See golang.org/issue/11111.
if string(tlsErr.RecordHeader[:]) == "HTTP/" {
err = errors.New("http: server gave HTTP response to HTTPS client")
err = ErrSchemeMismatch
}
}
return nil, didTimeout, err
Expand Down

0 comments on commit 00c8e88

Please sign in to comment.