mirror of
https://github.com/openfaas/faas.git
synced 2025-06-11 09:46:48 +00:00
Proxy fix - copy request headers into upstream
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
parent
ab33d80654
commit
37ef024df7
@ -58,8 +58,9 @@ func MakeForwardingProxyHandler(proxy *types.HTTPClientReverseProxy, metrics *me
|
||||
func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Client, baseURL string, requestURL string, timeout time.Duration) (int, error) {
|
||||
|
||||
upstreamReq, _ := http.NewRequest(r.Method, baseURL+requestURL, nil)
|
||||
copyHeaders(upstreamReq.Header, &r.Header)
|
||||
|
||||
upstreamReq.Header["X-Forwarded-For"] = []string{r.RequestURI}
|
||||
upstreamReq.Header["X-Forwarded-For"] = []string{r.RemoteAddr}
|
||||
|
||||
if r.Body != nil {
|
||||
defer r.Body.Close()
|
||||
@ -80,10 +81,7 @@ func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Cl
|
||||
defer res.Body.Close()
|
||||
}
|
||||
|
||||
// Populate any headers received
|
||||
for k, v := range res.Header {
|
||||
w.Header()[k] = v
|
||||
}
|
||||
copyHeaders(w.Header(), &res.Header)
|
||||
|
||||
// Write status code
|
||||
w.WriteHeader(res.StatusCode)
|
||||
@ -96,6 +94,14 @@ func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Cl
|
||||
return res.StatusCode, nil
|
||||
}
|
||||
|
||||
func copyHeaders(destination http.Header, source *http.Header) {
|
||||
for k, v := range *source {
|
||||
vClone := make([]string, len(v))
|
||||
copy(vClone, v)
|
||||
(destination)[k] = vClone
|
||||
}
|
||||
}
|
||||
|
||||
func getServiceName(urlValue string) string {
|
||||
var serviceName string
|
||||
forward := "/function/"
|
||||
|
Loading…
x
Reference in New Issue
Block a user