Propagate context to upstream request

Propagates the context to upstream requests so that
cancellation can cascade.

Closes: #1501 by @SpaWn2KiLl which was not signed-off.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2020-04-05 09:44:31 +01:00
parent 4c08240d9f
commit c44cb74cc7

View File

@ -123,7 +123,7 @@ func forwardRequest(w http.ResponseWriter,
log.Printf("forwardRequest: %s %s\n", upstreamReq.Host, upstreamReq.URL.String())
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()
res, resErr := proxyClient.Do(upstreamReq.WithContext(ctx))