Skip to content

Commit 00c8e88

Browse files
committed
net/http: expose "http: server gave HTTP response to HTTPS client" error
Expose "http: server gave HTTP response to HTTPS client" error as ErrSchemeMismatch, so that it can be compared with errors.Is . Fixes #44855 Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent eab9a77 commit 00c8e88

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/net/http/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ func (c *Client) transport() RoundTripper {
199199
return DefaultTransport
200200
}
201201

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

0 commit comments

Comments
 (0)