summaryrefslogtreecommitdiff
path: root/src/pkg/http/cgi/host.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/http/cgi/host.go')
-rw-r--r--src/pkg/http/cgi/host.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pkg/http/cgi/host.go b/src/pkg/http/cgi/host.go
index d36eaa19b..1d6382141 100644
--- a/src/pkg/http/cgi/host.go
+++ b/src/pkg/http/cgi/host.go
@@ -37,6 +37,7 @@ var osDefaultInheritEnv = map[string][]string{
"hpux": {"LD_LIBRARY_PATH", "SHLIB_PATH"},
"irix": {"LD_LIBRARY_PATH", "LD_LIBRARYN32_PATH", "LD_LIBRARY64_PATH"},
"linux": {"LD_LIBRARY_PATH"},
+ "openbsd": {"LD_LIBRARY_PATH"},
"solaris": {"LD_LIBRARY_PATH", "LD_LIBRARY_PATH_32", "LD_LIBRARY_PATH_64"},
"windows": {"SystemRoot", "COMSPEC", "PATHEXT", "WINDIR"},
}
@@ -68,6 +69,31 @@ type Handler struct {
PathLocationHandler http.Handler
}
+// removeLeadingDuplicates remove leading duplicate in environments.
+// It's possible to override environment like following.
+// cgi.Handler{
+// ...
+// Env: []string{"SCRIPT_FILENAME=foo.php"},
+// }
+func removeLeadingDuplicates(env []string) (ret []string) {
+ n := len(env)
+ for i := 0; i < n; i++ {
+ e := env[i]
+ s := strings.SplitN(e, "=", 2)[0]
+ found := false
+ for j := i + 1; j < n; j++ {
+ if s == strings.SplitN(env[j], "=", 2)[0] {
+ found = true
+ break
+ }
+ }
+ if !found {
+ ret = append(ret, e)
+ }
+ }
+ return
+}
+
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
root := h.Root
if root == "" {
@@ -149,6 +175,8 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
}
+ env = removeLeadingDuplicates(env)
+
var cwd, path string
if h.Dir != "" {
path = h.Path