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/httputil: ReverseProxy copyHeader() appends to pre-existing headers instead of overwriting them from target service's response. #66995

Closed
abiabsurd opened this issue Apr 23, 2024 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@abiabsurd
Copy link

Go version

go1.22.0

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/<REDACTED_USER>/Library/Caches/go-build'
GOENV='/Users/<REDACTED_USER>/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/<REDACTED_USER>/.asdf/installs/golang/1.22.2/packages/pkg/mod'
GONOPROXY='github.com/<REDACTED_ORG>/*'
GONOSUMDB='github.com/<REDACTED_ORG>/*'
GOOS='darwin'
GOPATH='/Users/<REDACTED_USER>/.asdf/installs/golang/1.22.2/packages'
GOPRIVATE='github.com/<REDACTED_ORG>/*'
GOPROXY='https://proxy.golang.org'
GOROOT='/Users/<REDACTED_USER>/.asdf/installs/golang/1.22.2/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/<REDACTED_USER>/.asdf/installs/golang/1.22.2/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/<REDACTED_USER>/dev/<REDACTED_PROJECT>/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0q/9rlm7rwn50zdtjst9zj2rwlw0000gq/T/go-build1228020991=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I used the NewSingleHostReverseProxy constructor to generate a *ReverseProxy to a target service, and then called ServeHTTP from an http handler func.

What did you see happen?

Header values for keys that pre-existed on the http.ResponseWriter passed to *ReverseProxy.ServeHTTP — for example, "Vary" and "Access-Control-Allow-Origin" — are duplicated in the final response due to the call to copyHeader(rw.Header(), res.Header), which appends to existing headers because it uses dst.Add(k, v) as opposed to dst.Set(k, v).

What did you expect to see?

I expected to see the target service's response headers copied directly to the final response, instead of appended to the pre-existing headers. If this is the correct intended behavior, then this can be fixed by changing dst.Add(k, v) in copyHeader() to dst.Set(k, v).

@joedian joedian added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 23, 2024
@seankhliao
Copy link
Member

Duplicate of #50730

@seankhliao seankhliao marked this as a duplicate of #50730 Apr 23, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
@abiabsurd
Copy link
Author

Sorry I didn't check the closed issues, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants