go: net/http: add ErrSchemeMismatch

What version of Go are you using (go version)?

$ go version
go version go1.16 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you expect to see?

I’d like to see the http: server gave HTTP response to HTTPS client error in the net/http package to be exposed as a constant that can be compared with errors.Is

https://github.com/golang/go/blob/f21be2fdc6f1becdbed1592ea0b245cdeedc5ac8/src/net/http/client.go#L262

Context

I’m working on a clone of Docker called nerdctl (contaiNERD ctl). I want to compare http: server gave HTTP response to HTTPS client with errors.Is, for ease of reimplementing dockerd --insecure-registries, which attempts HTTPS first and then falls back to HTTP.

What did you see instead?

The http: server gave HTTP response to HTTPS client error is not exposed.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

This is a proposed API change, so adding to the proposal process.

Specific proposal:

Add http.ErrSchemeMismatch, a distinguishable error that indicates an HTTPS server received what looks like an HTTP request. This converts an existing error to an exported, distinguishable symbol. See https://go.dev/cl/382117.

I’m fine with (2). Or (1) if we name it, say, ErrSchemeMismatch (“HTTP” in “ErrHTTPResponse” sounds too generic, as “HTTP” often also means “HTTPS”).

I wouldn’t want to see a new function. That’s too heavy in godoc for how fringe this is.