From fe3a347c07d2a85caefc4fd1432f5b368493d36d Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 2 Oct 2020 18:45:50 +0200 Subject: [PATCH] Pass through env from around the program Signed-off-by: Knut Ahlers --- main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 440ccf0..1c1b31d 100644 --- a/main.go +++ b/main.go @@ -67,20 +67,20 @@ func handleScriptCall(w http.ResponseWriter, r *http.Request) { } var ( - stdout = new(bytes.Buffer) - cmd = exec.Command(script) + stdout = new(bytes.Buffer) + 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.Stderr = os.Stderr 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 { http.Error(w, "Script execution failed, see log", http.StatusInternalServerError) return