Skip to content

Commit 2a78c9c

Browse files
francislavoiemholt
andauthored
httpcaddyfile: Allow nameless regexp placeholder shorthand (#6113)
Co-authored-by: Matt Holt <[email protected]>
1 parent 01d5568 commit 2a78c9c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

caddyconfig/httpcaddyfile/shorthands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewShorthandReplacer() ShorthandReplacer {
3333
{regexp.MustCompile(`{path\.([\w-]*)}`), "{http.request.uri.path.$1}"},
3434
{regexp.MustCompile(`{file\.([\w-]*)}`), "{http.request.uri.path.file.$1}"},
3535
{regexp.MustCompile(`{query\.([\w-]*)}`), "{http.request.uri.query.$1}"},
36-
{regexp.MustCompile(`{re\.([\w-]*)\.([\w-]*)}`), "{http.regexp.$1.$2}"},
36+
{regexp.MustCompile(`{re\.([\w-\.]*)}`), "{http.regexp.$1}"},
3737
{regexp.MustCompile(`{vars\.([\w-]*)}`), "{http.vars.$1}"},
3838
{regexp.MustCompile(`{rp\.([\w-\.]*)}`), "{http.reverse_proxy.$1}"},
3939
{regexp.MustCompile(`{err\.([\w-\.]*)}`), "{http.error.$1}"},

caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
localhost:80
2+
23
respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
4+
5+
@match path_regexp ^/foo(.*)$
6+
respond @match "{re.1}"
37
----------
48
{
59
"apps": {
@@ -22,6 +26,21 @@ respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
2226
{
2327
"handler": "subroute",
2428
"routes": [
29+
{
30+
"handle": [
31+
{
32+
"body": "{http.regexp.1}",
33+
"handler": "static_response"
34+
}
35+
],
36+
"match": [
37+
{
38+
"path_regexp": {
39+
"pattern": "^/foo(.*)$"
40+
}
41+
}
42+
]
43+
},
2544
{
2645
"handle": [
2746
{

0 commit comments

Comments
 (0)