golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.14k stars 17.69k forks source link

net/url: unsupported protocol scheme in header field #56027

Closed jnelle closed 2 years ago

jnelle commented 2 years ago

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

$ go 1.19.1

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jimbo/.cache/go-build"
GOENV="/home/jimbo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jimbo/go/pkg/mod"
GOOS="linux"
GOPATH="/home/jimbo/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/shared/dev/myfitnesspal/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build714340508=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a http wrapper for the MyFitnessPal API. When I'm trying to get a callback code which is located in the header, I'll get an error message. To reproduce clone the following repository and install the dependencies and then run:

go run main.go

What did you expect to see?

A response with status code 302 and a location header which contains the callback code.

What did you see instead?

I'll get the following error message:

net/url.Error {Op: "Post", URL: "mfp://identity/callback?code=XXXX", Err: error(*errors.errorString) *{s: "http2: unsupported scheme"}}

response variable is nil.

Screenshot 2022-10-04 130932

I know that this "mfp://" url is in headers, because I checked it with a proxy before (see screenshot below)

Screenshot 2022-10-04 130532

It looks like net/http is validating header values, which, if I understood it right, should'nt do it

ZekeLu commented 2 years ago

If the http client follows the redirect, it will see mfp://identify/.... which is invalid to the http client. I think you want to configure CheckRedirect of the http client to prevent it from following the redirect and handle the header yourself. See https://pkg.go.dev/net/http@go1.19.1#Client for documentation about CheckRedirect.

seankhliao commented 2 years ago

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

jnelle commented 2 years ago

Why isn't this a bug? @seankhliao

seankhliao commented 2 years ago

The client followed the redirect (default policy) and you haven't registered a RoundTripper for the given scheme, so it's an outgoing request error.