caddyhttp: Add split_path to file matcher (used by php_fastcgi) (#3302)

* matcher: Add `split_path` option to file matcher; used in php_fastcgi

* matcher: Skip try_files split if not the final part of the filename

* matcher: Add MatchFile tests

* matcher: Clarify SplitPath godoc
This commit is contained in:
Francis Lavoie
2020-04-27 16:46:46 -04:00
committed by GitHub
parent 83c85c53f5
commit 5ae1a5617c
9 changed files with 342 additions and 188 deletions

View File

@ -15,6 +15,7 @@
package caddyhttp
import (
"context"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
@ -30,6 +31,16 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddytls"
)
// NewTestReplacer creates a replacer for an http.Request
// for use in tests that are not in this package
func NewTestReplacer(req *http.Request) *caddy.Replacer {
repl := caddy.NewReplacer()
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
*req = *req.WithContext(ctx)
addHTTPVarsToReplacer(repl, req, nil)
return repl
}
func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.ResponseWriter) {
httpVars := func(key string) (interface{}, bool) {
if req != nil {