aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httputil/reverseproxy.go
diff options
context:
space:
mode:
authorSALLEYRON Julien <julien.salleyron@gmail.com>2018-12-03 20:46:23 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-12-03 21:45:17 +0000
commit48399cae9f828668bd2c010dc46e4767f2acd011 (patch)
tree5b9dc36b502d50255144030e20f809cad3a1c764 /src/net/http/httputil/reverseproxy.go
parenta48a15cd502395627293f85cdbe23aebc3e7e95f (diff)
downloadgo-48399cae9f828668bd2c010dc46e4767f2acd011.tar.gz
go-48399cae9f828668bd2c010dc46e4767f2acd011.zip
net/http/httputil: fix unannounced trailers when body is empty
Fix unannounced trailers when body is empty and without announced trailers. Fixes #29031 Change-Id: If49951a42fe56d4be4436a999627db4c2678659d GitHub-Last-Rev: 3469adc8f5fd977438350274134950687853a468 GitHub-Pull-Request: golang/go#29032 Reviewed-on: https://go-review.googlesource.com/c/151898 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r--src/net/http/httputil/reverseproxy.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go
index f0607a68ea..5d07ba3d36 100644
--- a/src/net/http/httputil/reverseproxy.go
+++ b/src/net/http/httputil/reverseproxy.go
@@ -282,14 +282,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
rw.WriteHeader(res.StatusCode)
- if len(res.Trailer) > 0 {
- // Force chunking if we saw a response trailer.
- // This prevents net/http from calculating the length for short
- // bodies and adding a Content-Length.
- if fl, ok := rw.(http.Flusher); ok {
- fl.Flush()
- }
- }
+
err = p.copyResponse(rw, res.Body, p.flushInterval(req, res))
if err != nil {
defer res.Body.Close()
@@ -304,6 +297,15 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
res.Body.Close() // close now, instead of defer, to populate res.Trailer
+ if len(res.Trailer) > 0 {
+ // Force chunking if we saw a response trailer.
+ // This prevents net/http from calculating the length for short
+ // bodies and adding a Content-Length.
+ if fl, ok := rw.(http.Flusher); ok {
+ fl.Flush()
+ }
+ }
+
if len(res.Trailer) == announcedTrailers {
copyHeader(rw.Header(), res.Trailer)
return