summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/replacer.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-04-27 16:46:46 -0400
committerGitHub <noreply@github.com>2020-04-27 14:46:46 -0600
commit5ae1a5617c4bb1deef22cb3658ee581bb7dbf367 (patch)
tree84bb5582a6b1f961ad670f290d020b747ff26cee /modules/caddyhttp/replacer.go
parent83c85c53f583906e438bb9eb30fc0ab57bf59108 (diff)
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
Diffstat (limited to 'modules/caddyhttp/replacer.go')
-rw-r--r--modules/caddyhttp/replacer.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index b83977c..670b2e3 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -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 {