Skip to content

Commit 22879fc

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 4f4a9c7 commit 22879fc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

api/next/44855.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg net/http, var ErrSchemeMismatch error #44855

src/net/http/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func (c *Client) transport() RoundTripper {
204204
return DefaultTransport
205205
}
206206

207+
// ErrSchemeMismatch is returned when a server returns an HTTP response to an HTTPS client.
208+
var ErrSchemeMismatch = errors.New("http: server gave HTTP response to HTTPS client")
209+
207210
// send issues an HTTP request.
208211
// Caller should close resp.Body when done reading from it.
209212
func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, didTimeout func() bool, err error) {
@@ -265,7 +268,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, d
265268
// response looks like HTTP and give a more helpful error.
266269
// See golang.org/issue/11111.
267270
if string(tlsErr.RecordHeader[:]) == "HTTP/" {
268-
err = errors.New("http: server gave HTTP response to HTTPS client")
271+
err = ErrSchemeMismatch
269272
}
270273
}
271274
return nil, didTimeout, err

0 commit comments

Comments
 (0)