Skip to content

net/http: expose "http: server gave HTTP response to HTTPS client" error #50939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/next/44855.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg net/http, var ErrSchemeMismatch error #44855
5 changes: 4 additions & 1 deletion src/net/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func (c *Client) transport() RoundTripper {
return DefaultTransport
}

// ErrSchemeMismatch is returned when a server returns an HTTP response to an 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 @@ -265,7 +268,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