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) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (VMware)
2018-03-27 21:12:38 +01:00
parent 58bd87c811
commit 65ed8457af

View File

@ -58,15 +58,18 @@ func buildUpstreamRequest(r *http.Request, url string) *http.Request {
upstreamReq.Header["X-Forwarded-For"] = []string{r.RemoteAddr} upstreamReq.Header["X-Forwarded-For"] = []string{r.RemoteAddr}
if r.Body != nil { if r.Body != nil {
defer r.Body.Close()
upstreamReq.Body = r.Body upstreamReq.Body = r.Body
} }
return upstreamReq return upstreamReq
} }
func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Client, baseURL string, requestURL string, timeout time.Duration) (int, error) { 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) upstreamReq := buildUpstreamRequest(r, baseURL+requestURL)
if upstreamReq.Body != nil {
defer upstreamReq.Body.Close()
}
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()