net/http/httputil: ReverseProxy copyHeader() appends to pre-existing headers instead of overwriting them from target service's response. #66995
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go1.22.0
Output of
go env
in your module/workspace:What did you do?
I used the
NewSingleHostReverseProxy
constructor to generate a*ReverseProxy
to atarget
service, and then calledServeHTTP
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 tocopyHeader(rw.Header(), res.Header)
, which appends to existing headers because it usesdst.Add(k, v)
as opposed todst.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)
incopyHeader()
todst.Set(k, v)
.The text was updated successfully, but these errors were encountered: