Add headers to env for default functions

This commit is contained in:
Owen Cliffe
2017-09-06 13:59:10 +01:00
parent 808c031b6f
commit 33060bcb9e

View File

@@ -103,12 +103,24 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
envVars[toEnvName("PARAM", param.Key)] = param.Value
}
var headerVars = make(map[string]string)
for k, v := range req.Header {
joinedHeader := strings.Join(v,",")
headerVars[toEnvName("HEADER",k)] = joinedHeader
}
// add all the env vars we build to the request headers
// TODO should we save req.Headers and copy OVER app.Config / route.Config ?
for k, v := range envVars {
req.Header.Add(k, v)
}
for k,v := range headerVars {
envVars[k] = v
}
// TODO this relies on ordering of opts, but tests make sure it works, probably re-plumb/destroy headers
if rw, ok := c.w.(http.ResponseWriter); ok {
rw.Header().Add("FN_CALL_ID", id)