mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
caddyhttp: add placeholder {http.request.orig_uri.path.*} (#5161)
This commit is contained in:
parent
a3ae146cbd
commit
ed503118dd
1 changed files with 30 additions and 8 deletions
|
@ -266,6 +266,27 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
|
||||||
return pathParts[idx], true
|
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
|
// middleware variables
|
||||||
if strings.HasPrefix(key, varsReplPrefix) {
|
if strings.HasPrefix(key, varsReplPrefix) {
|
||||||
varName := key[len(varsReplPrefix):]
|
varName := key[len(varsReplPrefix):]
|
||||||
|
@ -471,12 +492,13 @@ func (rid *requestID) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
reqCookieReplPrefix = "http.request.cookie."
|
reqCookieReplPrefix = "http.request.cookie."
|
||||||
reqHeaderReplPrefix = "http.request.header."
|
reqHeaderReplPrefix = "http.request.header."
|
||||||
reqHostLabelsReplPrefix = "http.request.host.labels."
|
reqHostLabelsReplPrefix = "http.request.host.labels."
|
||||||
reqTLSReplPrefix = "http.request.tls."
|
reqTLSReplPrefix = "http.request.tls."
|
||||||
reqURIPathReplPrefix = "http.request.uri.path."
|
reqURIPathReplPrefix = "http.request.uri.path."
|
||||||
reqURIQueryReplPrefix = "http.request.uri.query."
|
reqURIQueryReplPrefix = "http.request.uri.query."
|
||||||
respHeaderReplPrefix = "http.response.header."
|
respHeaderReplPrefix = "http.response.header."
|
||||||
varsReplPrefix = "http.vars."
|
varsReplPrefix = "http.vars."
|
||||||
|
reqOrigURIPathReplPrefix = "http.request.orig_uri.path."
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue