]> Cypherpunks repositories - gostls13.git/commitdiff
http/cgi: pass some default environment variables
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 22 Apr 2011 18:02:33 +0000 (11:02 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 22 Apr 2011 18:02:33 +0000 (11:02 -0700)
This isn't really part of RFC 3875 but matches
the behavior of Apache, et al.

R=iant, iant2
CC=golang-dev
https://golang.org/cl/4435065

src/pkg/http/cgi/host.go
src/pkg/http/cgi/matryoshka_test.go

index 1ab5716766c25e316f53da12db9eb6ed05a033ac..35fbde705a03d258fc0f106590f11cc571afdb8a 100644 (file)
@@ -25,12 +25,21 @@ import (
        "os"
        "path/filepath"
        "regexp"
+       "runtime"
        "strconv"
        "strings"
 )
 
 var trailingPort = regexp.MustCompile(`:([0-9]+)$`)
 
+var osDefaultInheritEnv = map[string][]string{
+       "darwin":  []string{"DYLD_LIBRARY_PATH"},
+       "freebsd": []string{"LD_LIBRARY_PATH"},
+       "hpux":    []string{"LD_LIBRARY_PATH", "SHLIB_PATH"},
+       "linux":   []string{"LD_LIBRARY_PATH"},
+       "windows": []string{"SystemRoot", "COMSPEC", "PATHEXT", "WINDIR"},
+}
+
 // Handler runs an executable in a subprocess with a CGI environment.
 type Handler struct {
        Path string // path to the CGI executable
@@ -111,12 +120,24 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
                env = append(env, h.Env...)
        }
 
+       path := os.Getenv("PATH")
+       if path == "" {
+               path = "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
+       }
+       env = append(env, "PATH="+path)
+
        for _, e := range h.InheritEnv {
                if v := os.Getenv(e); v != "" {
                        env = append(env, e+"="+v)
                }
        }
 
+       for _, e := range osDefaultInheritEnv[runtime.GOOS] {
+               if v := os.Getenv(e); v != "" {
+                       env = append(env, e+"="+v)
+               }
+       }
+
        cwd, pathBase := filepath.Split(h.Path)
        if cwd == "" {
                cwd = "."
index 548c050d41c22ed6f6f4bc590e1a7ddb358c5bdf..3e4a6addfa5dd182ff57bac33ed4cc0632954650 100644 (file)
@@ -22,14 +22,6 @@ func TestHostingOurselves(t *testing.T) {
                Path: os.Args[0],
                Root: "/test.go",
                Args: []string{"-test.run=TestBeChildCGIProcess"},
-               // When using a shared library with gccgo, make sure
-               // we can still find the library when we exec
-               // ourselves.
-               InheritEnv: []string{
-                       "LD_LIBRARY_PATH",
-                       "SHLIB_PATH",
-                       "DYLD_LIBRARY_PATH",
-               },
        }
        expectedMap := map[string]string{
                "test":                  "Hello CGI-in-CGI",