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
Closed

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

dravenk opened this issue Sep 28, 2018 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@dravenk
Copy link

dravenk 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==]
@ghost
Copy link

ghost 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 katiehockman added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 28, 2018
@katiehockman
Copy link
Contributor

/cc @bradfitz

@bradfitz
Copy link
Contributor

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.

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 28, 2018
@dravenk
Copy link
Author

dravenk 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
Copy link
Author

dravenk commented Sep 29, 2018

Add the issue of reference https://codereview.appspot.com/4185053/#msg5

@dravenk
Copy link
Author

dravenk commented Sep 29, 2018

Thank you for your patience

@dravenk dravenk closed this as completed Sep 29, 2018
@golang golang locked and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants