From 447d0ce0e2b587dc97fabf2aefe68f783e871521 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Fri, 1 May 2015 19:55:47 +0100 Subject: [PATCH] fastcgi: user defined environment variables --- middleware/fastcgi/fastcgi.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 984dcb89..7bb241b9 100644 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -200,6 +200,11 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, path string) (map[string]s "SCRIPT_NAME": scriptName, } + // Add env variables from config + for _, envVar := range rule.EnvVars { + env[envVar[0]] = envVar[1] + } + // Add all HTTP headers to env variables for field, val := range r.Header { header := strings.ToUpper(field) @@ -253,6 +258,12 @@ func parse(c middleware.Controller) ([]Rule, error) { return rules, c.ArgErr() } rule.IndexFile = c.Val() + case "env": + envArgs := c.RemainingArgs() + if len(envArgs) < 2 { + return rules, c.ArgErr() + } + rule.EnvVars = append(rule.EnvVars, [2]string{envArgs[0], envArgs[1]}) } } @@ -295,6 +306,9 @@ type Rule struct { // If the URL does not indicate a file, an index file with this name will be assumed. IndexFile string + + // Environment Variables + EnvVars [][2]string } var headerNameReplacer = strings.NewReplacer(" ", "_", "-", "_")