mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Merge pull request #34 from abiosoft/master
fastcgi: user defined environment variables
This commit is contained in:
commit
9e3852f21c
1 changed files with 14 additions and 0 deletions
|
@ -200,6 +200,11 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, path string) (map[string]s
|
||||||
"SCRIPT_NAME": scriptName,
|
"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
|
// Add all HTTP headers to env variables
|
||||||
for field, val := range r.Header {
|
for field, val := range r.Header {
|
||||||
header := strings.ToUpper(field)
|
header := strings.ToUpper(field)
|
||||||
|
@ -253,6 +258,12 @@ func parse(c middleware.Controller) ([]Rule, error) {
|
||||||
return rules, c.ArgErr()
|
return rules, c.ArgErr()
|
||||||
}
|
}
|
||||||
rule.IndexFile = c.Val()
|
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.
|
// If the URL does not indicate a file, an index file with this name will be assumed.
|
||||||
IndexFile string
|
IndexFile string
|
||||||
|
|
||||||
|
// Environment Variables
|
||||||
|
EnvVars [][2]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var headerNameReplacer = strings.NewReplacer(" ", "_", "-", "_")
|
var headerNameReplacer = strings.NewReplacer(" ", "_", "-", "_")
|
||||||
|
|
Loading…
Reference in a new issue