mirror of
https://github.com/Luzifer/local-functions.git
synced 2024-11-10 01:00:07 +00:00
Pass through env from around the program
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
6dea0a3fbd
commit
fe3a347c07
1 changed files with 8 additions and 8 deletions
16
main.go
16
main.go
|
@ -67,20 +67,20 @@ func handleScriptCall(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stdout = new(bytes.Buffer)
|
stdout = new(bytes.Buffer)
|
||||||
cmd = exec.Command(script)
|
cmd = exec.Command(script)
|
||||||
|
envVars = env.ListToMap(os.Environ())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
envVars["ACCEPT"] = r.Header.Get("Accept")
|
||||||
|
envVars["CONTENT_TYPE"] = r.Header.Get("Content-Type")
|
||||||
|
envVars["METHOD"] = r.Method
|
||||||
|
|
||||||
|
cmd.Env = env.MapToList(envVars)
|
||||||
cmd.Stdout = stdout
|
cmd.Stdout = stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Stdin = r.Body
|
cmd.Stdin = r.Body
|
||||||
|
|
||||||
cmd.Env = env.MapToList(map[string]string{
|
|
||||||
"ACCEPT": r.Header.Get("Accept"),
|
|
||||||
"CONTENT_TYPE": r.Header.Get("Content-Type"),
|
|
||||||
"METHOD": r.Method,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
http.Error(w, "Script execution failed, see log", http.StatusInternalServerError)
|
http.Error(w, "Script execution failed, see log", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue