summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Hartland <steven.hartland@multiplay.co.uk>2015-09-25 08:51:50 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2015-10-14 15:10:09 +0000
commit61860508add795c86059faa67d90bd556a3d49bf (patch)
treeb754630087fcfe2ebb85df550f58b987b6a13fae
parent1d765b77a04fb12c2d97e0a8c9491de2bbfcbacc (diff)
downloadgo-git-61860508add795c86059faa67d90bd556a3d49bf.tar.gz
net/http/cgi: make provided Env override even system env vars
Allow all CGI environment settings from the inherited set and default inherited set to be overridden including PATH by Env. Change-Id: Ief8d33247b879fa87a8bfd6416d4813116db98de Reviewed-on: https://go-review.googlesource.com/14959 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/net/http/cgi/host.go8
-rw-r--r--src/net/http/cgi/host_test.go4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/net/http/cgi/host.go b/src/net/http/cgi/host.go
index 4efbe7abee..1ae66e097c 100644
--- a/src/net/http/cgi/host.go
+++ b/src/net/http/cgi/host.go
@@ -159,10 +159,6 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
env = append(env, "CONTENT_TYPE="+ctype)
}
- if h.Env != nil {
- env = append(env, h.Env...)
- }
-
envPath := os.Getenv("PATH")
if envPath == "" {
envPath = "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
@@ -181,6 +177,10 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
}
+ if h.Env != nil {
+ env = append(env, h.Env...)
+ }
+
env = removeLeadingDuplicates(env)
var cwd, path string
diff --git a/src/net/http/cgi/host_test.go b/src/net/http/cgi/host_test.go
index 4aa67e4e5f..8a82789fd3 100644
--- a/src/net/http/cgi/host_test.go
+++ b/src/net/http/cgi/host_test.go
@@ -487,12 +487,14 @@ func TestEnvOverride(t *testing.T) {
Args: []string{cgifile},
Env: []string{
"SCRIPT_FILENAME=" + cgifile,
- "REQUEST_URI=/foo/bar"},
+ "REQUEST_URI=/foo/bar",
+ "PATH=/wibble"},
}
expectedMap := map[string]string{
"cwd": cwd,
"env-SCRIPT_FILENAME": cgifile,
"env-REQUEST_URI": "/foo/bar",
+ "env-PATH": "/wibble",
}
runCgiTest(t, h, "GET /test.cgi HTTP/1.0\nHost: example.com\n\n", expectedMap)
}