Pass through env from around the program

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-10-02 18:45:50 +02:00
parent 6dea0a3fbd
commit fe3a347c07
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

12
main.go
View file

@ -69,18 +69,18 @@ func handleScriptCall(w http.ResponseWriter, r *http.Request) {
var (
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