Skip to content

Commit

Permalink
httpcaddyfile: Allow nameless regexp placeholder shorthand (#6113)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
  • Loading branch information
francislavoie and mholt authored Mar 5, 2024
1 parent 01d5568 commit 2a78c9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion caddyconfig/httpcaddyfile/shorthands.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewShorthandReplacer() ShorthandReplacer {
{regexp.MustCompile(`{path\.([\w-]*)}`), "{http.request.uri.path.$1}"},
{regexp.MustCompile(`{file\.([\w-]*)}`), "{http.request.uri.path.file.$1}"},
{regexp.MustCompile(`{query\.([\w-]*)}`), "{http.request.uri.query.$1}"},
{regexp.MustCompile(`{re\.([\w-]*)\.([\w-]*)}`), "{http.regexp.$1.$2}"},
{regexp.MustCompile(`{re\.([\w-\.]*)}`), "{http.regexp.$1}"},
{regexp.MustCompile(`{vars\.([\w-]*)}`), "{http.vars.$1}"},
{regexp.MustCompile(`{rp\.([\w-\.]*)}`), "{http.reverse_proxy.$1}"},
{regexp.MustCompile(`{err\.([\w-\.]*)}`), "{http.error.$1}"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
localhost:80

respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"

@match path_regexp ^/foo(.*)$
respond @match "{re.1}"
----------
{
"apps": {
Expand All @@ -22,6 +26,21 @@ respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"body": "{http.regexp.1}",
"handler": "static_response"
}
],
"match": [
{
"path_regexp": {
"pattern": "^/foo(.*)$"
}
}
]
},
{
"handle": [
{
Expand Down

0 comments on commit 2a78c9c

Please sign in to comment.