var trailingPort = regexp.MustCompile(`:([0-9]+)$`)
-var osDefaultInheritEnv = getOSDefaultInheritEnv()
-
-// TODO(mdempsky): Revert CL 522935 after #62277 is fixed.
-func getOSDefaultInheritEnv() []string {
+var osDefaultInheritEnv = func() []string {
switch runtime.GOOS {
case "darwin", "ios":
return []string{"DYLD_LIBRARY_PATH"}
return []string{"SystemRoot", "COMSPEC", "PATHEXT", "WINDIR"}
}
return nil
-}
+}()
// Handler runs an executable in a subprocess with a CGI environment.
type Handler struct {
}
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
- root := h.Root
- if root == "" {
- root = "/"
- }
-
if len(req.TransferEncoding) > 0 && req.TransferEncoding[0] == "chunked" {
rw.WriteHeader(http.StatusBadRequest)
rw.Write([]byte("Chunked request bodies are not supported by CGI."))
return
}
- pathInfo := req.URL.Path
- if root != "/" && strings.HasPrefix(pathInfo, root) {
- pathInfo = pathInfo[len(root):]
- }
+ root := strings.TrimRight(h.Root, "/")
+ pathInfo := strings.TrimPrefix(req.URL.Path, root)
port := "80"
+ if req.TLS != nil {
+ port = "443"
+ }
if matches := trailingPort.FindStringSubmatch(req.Host); len(matches) != 0 {
port = matches[1]
}