From 65ed8457af33fe89382e1f095608d60735102c82 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" Date: Tue, 27 Mar 2018 21:12:38 +0100 Subject: [PATCH] Fix issue in passing-through of proxy body Proxy body was being passed correctly due to placement of defer statement. This has been moved into outer scope to resolve issue. Tested with new e2e tests in certifier component. Signed-off-by: Alex Ellis (VMware) --- gateway/handlers/forwarding_proxy.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gateway/handlers/forwarding_proxy.go b/gateway/handlers/forwarding_proxy.go index c5a7d3b3..59367f37 100644 --- a/gateway/handlers/forwarding_proxy.go +++ b/gateway/handlers/forwarding_proxy.go @@ -58,15 +58,18 @@ func buildUpstreamRequest(r *http.Request, url string) *http.Request { upstreamReq.Header["X-Forwarded-For"] = []string{r.RemoteAddr} if r.Body != nil { - defer r.Body.Close() upstreamReq.Body = r.Body } + return upstreamReq } func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Client, baseURL string, requestURL string, timeout time.Duration) (int, error) { upstreamReq := buildUpstreamRequest(r, baseURL+requestURL) + if upstreamReq.Body != nil { + defer upstreamReq.Body.Close() + } ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel()