From 33060bcb9eb95a4a71244f99a4b7b70236f35eae Mon Sep 17 00:00:00 2001 From: Owen Cliffe Date: Wed, 6 Sep 2017 13:59:10 +0100 Subject: [PATCH] Add headers to env for default functions --- api/agent/call.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/agent/call.go b/api/agent/call.go index e19a36979..cde39c070 100644 --- a/api/agent/call.go +++ b/api/agent/call.go @@ -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)