]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/net/http/cgi/host.go
net/http/cgi: the PATH_INFO should be empty or start with a slash
[gostls13.git] / src / net / http / cgi / host.go
index 073952a7bd40f15bb75cba793c26537f55391923..ef222ab73a75c0ce2c6d897bd635470f503ca071 100644 (file)
@@ -115,23 +115,19 @@ func removeLeadingDuplicates(env []string) (ret []string) {
 }
 
 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]
        }