aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httputil/reverseproxy.go
diff options
context:
space:
mode:
authorTristan Colgate <tcolgate@gmail.com>2017-05-20 14:50:06 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2017-05-22 18:34:09 +0000
commit1611839b29a5447f3132e93f14c75b1639a34490 (patch)
tree2b5f941878c053e678fdbb1726d4d1ba6f72158c /src/net/http/httputil/reverseproxy.go
parentbc495c5751201854366b422e5a642ac55b42414a (diff)
downloadgo-1611839b29a5447f3132e93f14c75b1639a34490.tar.gz
go-1611839b29a5447f3132e93f14c75b1639a34490.zip
net/http/httputil: ReverseProxy should pass on unannounced Trailers
Trailers that are not announced in the Trailer must be passed on to the downstream client. Rather than iterate over each and find missing trailer values, this re-adds all trailers to the headers if there is a disparity between the number of announced trailers and the final number. This fixes #20437 Change-Id: I867e85f45feff68616a9a9bd6f65f12d73825eb7 Reviewed-on: https://go-review.googlesource.com/43712 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r--src/net/http/httputil/reverseproxy.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go
index 488db97313..fd78d45602 100644
--- a/src/net/http/httputil/reverseproxy.go
+++ b/src/net/http/httputil/reverseproxy.go
@@ -233,7 +233,8 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// The "Trailer" header isn't included in the Transport's response,
// at least for *http.Transport. Build it up from Trailer.
- if len(res.Trailer) > 0 {
+ announcedTrailers := len(res.Trailer)
+ if announcedTrailers > 0 {
trailerKeys := make([]string, 0, len(res.Trailer))
for k := range res.Trailer {
trailerKeys = append(trailerKeys, k)
@@ -252,7 +253,18 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
p.copyResponse(rw, res.Body)
res.Body.Close() // close now, instead of defer, to populate res.Trailer
- copyHeader(rw.Header(), res.Trailer)
+
+ if len(res.Trailer) == announcedTrailers {
+ copyHeader(rw.Header(), res.Trailer)
+ return
+ }
+
+ for k, vv := range res.Trailer {
+ k = http.TrailerPrefix + k
+ for _, v := range vv {
+ rw.Header().Add(k, v)
+ }
+ }
}
func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {