mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-08 13:38:29 +08:00
Merge remote-tracking branch 'upstream/master'
Conflicts: middleware/fastcgi/fastcgi.go
This commit is contained in:
commit
bb85a84561
|
@ -167,9 +167,17 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip PATH_INFO from SCRIPT_NAME
|
// Strip PATH_INFO from SCRIPT_NAME
|
||||||
indexPathInfo := strings.LastIndex(scriptName, pathInfo)
|
scriptName = strings.TrimSuffix(scriptName, pathInfo)
|
||||||
if indexPathInfo != -1 {
|
|
||||||
scriptName = scriptName[:indexPathInfo]
|
// Get the request URI. The request URI might be as it came in over the wire,
|
||||||
|
// or it might have been rewritten internally by the rewrite middleware (see issue #256).
|
||||||
|
// If it was rewritten, there will be a header indicating the original URL,
|
||||||
|
// which is needed to get the correct RequestURI value for PHP apps.
|
||||||
|
const internalRewriteFieldName = "Caddy-Rewrite-Original-URI"
|
||||||
|
reqURI := r.URL.RequestURI()
|
||||||
|
if origURI := r.Header.Get(internalRewriteFieldName); origURI != "" {
|
||||||
|
reqURI = origURI
|
||||||
|
r.Header.Del(internalRewriteFieldName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some variables are unused but cleared explicitly to prevent
|
// Some variables are unused but cleared explicitly to prevent
|
||||||
|
@ -198,7 +206,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string]
|
||||||
"DOCUMENT_ROOT": h.AbsRoot,
|
"DOCUMENT_ROOT": h.AbsRoot,
|
||||||
"DOCUMENT_URI": docURI,
|
"DOCUMENT_URI": docURI,
|
||||||
"HTTP_HOST": r.Host, // added here, since not always part of headers
|
"HTTP_HOST": r.Host, // added here, since not always part of headers
|
||||||
"REQUEST_URI": r.URL.RequestURI(),
|
"REQUEST_URI": reqURI,
|
||||||
"SCRIPT_FILENAME": scriptFilename,
|
"SCRIPT_FILENAME": scriptFilename,
|
||||||
"SCRIPT_NAME": scriptName,
|
"SCRIPT_NAME": scriptName,
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ func NewSimpleRule(from, to string) SimpleRule {
|
||||||
// Rewrite rewrites the internal location of the current request.
|
// Rewrite rewrites the internal location of the current request.
|
||||||
func (s SimpleRule) Rewrite(r *http.Request) bool {
|
func (s SimpleRule) Rewrite(r *http.Request) bool {
|
||||||
if s.From == r.URL.Path {
|
if s.From == r.URL.Path {
|
||||||
|
// take note of this rewrite for internal use by fastcgi
|
||||||
|
// all we need is the URI, not full URL
|
||||||
|
r.Header.Set("Caddy-Rewrite-Original-URI", r.URL.RequestURI())
|
||||||
r.URL.Path = s.To
|
r.URL.Path = s.To
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -129,6 +132,10 @@ func (r *RegexpRule) Rewrite(req *http.Request) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// take note of this rewrite for internal use by fastcgi
|
||||||
|
// all we need is the URI, not full URL
|
||||||
|
req.Header.Set("Caddy-Rewrite-Original-URI", req.URL.RequestURI())
|
||||||
|
|
||||||
// perform rewrite
|
// perform rewrite
|
||||||
req.URL.Path = url.Path
|
req.URL.Path = url.Path
|
||||||
if url.RawQuery != "" {
|
if url.RawQuery != "" {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/bradfitz/http2"
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server represents an instance of a server, which serves
|
// Server represents an instance of a server, which serves
|
||||||
|
|
Loading…
Reference in New Issue
Block a user