summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorXYenon <register@xyenon.bid>2022-10-25 01:57:50 +0800
committerGitHub <noreply@github.com>2022-10-24 11:57:50 -0600
commited503118dd8bd2dda2e780bdf7a0ada74338a462 (patch)
treeffaca5caa3efcd75de40827b8589d142c20e6e44 /modules
parenta3ae146cbdf2cfbdbdf5feea52e8bf407cce2b31 (diff)
caddyhttp: add placeholder {http.request.orig_uri.path.*} (#5161)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/replacer.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index 9ea5f77..e89c502 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -266,6 +266,27 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
return pathParts[idx], true
}
+ // orig uri path parts
+ if strings.HasPrefix(key, reqOrigURIPathReplPrefix) {
+ idxStr := key[len(reqOrigURIPathReplPrefix):]
+ idx, err := strconv.Atoi(idxStr)
+ if err != nil {
+ return "", false
+ }
+ or, _ := req.Context().Value(OriginalRequestCtxKey).(http.Request)
+ pathParts := strings.Split(or.URL.Path, "/")
+ if len(pathParts) > 0 && pathParts[0] == "" {
+ pathParts = pathParts[1:]
+ }
+ if idx < 0 {
+ return "", false
+ }
+ if idx >= len(pathParts) {
+ return "", true
+ }
+ return pathParts[idx], true
+ }
+
// middleware variables
if strings.HasPrefix(key, varsReplPrefix) {
varName := key[len(varsReplPrefix):]
@@ -471,12 +492,13 @@ func (rid *requestID) String() string {
}
const (
- reqCookieReplPrefix = "http.request.cookie."
- reqHeaderReplPrefix = "http.request.header."
- reqHostLabelsReplPrefix = "http.request.host.labels."
- reqTLSReplPrefix = "http.request.tls."
- reqURIPathReplPrefix = "http.request.uri.path."
- reqURIQueryReplPrefix = "http.request.uri.query."
- respHeaderReplPrefix = "http.response.header."
- varsReplPrefix = "http.vars."
+ reqCookieReplPrefix = "http.request.cookie."
+ reqHeaderReplPrefix = "http.request.header."
+ reqHostLabelsReplPrefix = "http.request.host.labels."
+ reqTLSReplPrefix = "http.request.tls."
+ reqURIPathReplPrefix = "http.request.uri.path."
+ reqURIQueryReplPrefix = "http.request.uri.query."
+ respHeaderReplPrefix = "http.response.header."
+ varsReplPrefix = "http.vars."
+ reqOrigURIPathReplPrefix = "http.request.orig_uri.path."
)