From 5ae1a5617c4bb1deef22cb3658ee581bb7dbf367 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 27 Apr 2020 16:46:46 -0400 Subject: 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 --- modules/caddyhttp/replacer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'modules/caddyhttp/replacer.go') 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 { -- cgit v1.2.3