mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-03 02:23:41 +08:00
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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user