Description
The http
library in Go 1.7 HTTP client does not handle preserving headers correctly when it gets redirected. If a HTTP request gets redirected, the second request to the new location does not contain all the headers the previous request did.
This is not an issue in Go 1.8. Running the below steps to test it in 1.8 results in no problems.
What version of Go are you using (go version
)?
go version go1.7.5 darwin/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/imuser/goenv"
GORACE=""
GOROOT="/Users/imuser/go1.7/go"
GOTOOLDIR="/Users/imuser/go1.7/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/m2/907y66gx3v56c6njghgyvlx80000gq/T/go-build725648257=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
What did you do?
Minimal repo with reproduction of the issue found here: https://github.com/fsufitch/go-redirbug
- Start a server with
go run server.go
(in theserver/
folder). This is a simple server that redirects from/foo
to/foo/
. It responds to/foo/
by checking the "Authorization" header for a valid value, and prints a result appropriate to that comparison. - Run the client with
go run client.go
(in theclient/
folder). This is a simple client that queries the aforementioned server's/foo
endpoint, with the correct authorization.
With unit tests:
Run the client's tests using go test
in the client/
folder.
What did you expect to see?
The client should successfully complete the query to the server, getting redirected to /foo/
and providing the correct header, leading to an OK response from the server.
With unit tests:
When running the tests, both tests (TestQueryNoSlash
and TestQueryWithSlash
) pass.
What did you see instead?
The request that the /foo/
endpoint on the server receives does not include an "Authorization" header. This causes the server to reply with a 401 Unauthorized to the request instead of the expected OK.
With unit tests:
TestQueryNoSlash
(which includes the redirect) fails, while TestQueryWithSlash
(which does not redirect) does not.