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 (
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue