Skip to content
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

net/http: ~~SetBasicAuth got an incorrect type of value~~ #27919

Closed
dravenk opened this issue Sep 28, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@dravenk
Copy link

commented Sep 28, 2018

Please answer these questions before submitting your issue. Thanks!
I wrote a proxy server and my colleagues found that the authentication information being forwarded was wrong. I compared Mozilla's documentation Authorization and found that the SetBasicAuth method was not in the form of an instance.
Example.

Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l

But SetBasicAuth result is the following.

Authorization:[Basic c3NvX2FkbWluOjt4ODg4OA==]

The value of the Authorization in the example is a string, but what SetBasicAuth gets is a []string.

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build572473428=/tmp/go-build -gno-record-gcc-switches"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

func (s *Server) ProxyServer(w http.ResponseWriter, r *http.Request) {
	director := func(req *http.Request) {
		req.SetBasicAuth(s.User, s.Pass)
		req.URL.Scheme = target.Scheme
		req.URL.Host = target.Host
		req.Host = target.Host
	}
	proxy := &httputil.ReverseProxy{Director: director}
	proxy.ServeHTTP(w, r)
}

What did you expect to see?

The value of Authorization is a string type.

Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l

What did you see instead?

The value of Authorization is a []string type.

Authorization:[Basic c3NvX2FkbWluOjt4ODg4OA==]
@bontibon

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

That appears to be just the fmt representation of the http.Header.

What specifically are you seeing that value? Are you sure you're not just reading debugging information?

@katiehockman katiehockman changed the title SetBasicAuth got an incorrect type of value net/http: SetBasicAuth got an incorrect type of value Sep 28, 2018

@katiehockman

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

/cc @bradfitz

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 28, 2018

Yeah, I agree with @bontibon. I think you're just getting confused by your debug output. Please show a complete & minimal program with the problem.

@dravenk

This comment has been minimized.

Copy link
Author

commented Sep 29, 2018

I'm very sorry that it turned out not to be a problem with SetBasicAuth. But I have a question, why is the type of header a map[string][]string?

@dravenk dravenk changed the title net/http: SetBasicAuth got an incorrect type of value net/http: ~~SetBasicAuth got an incorrect type of value~~ Sep 29, 2018

@dravenk

This comment has been minimized.

Copy link
Author

commented Sep 29, 2018

@dravenk

This comment has been minimized.

Copy link
Author

commented Sep 29, 2018

Thank you for your patience

@dravenk dravenk closed this Sep 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.