aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2024-03-05 18:37:14 -0500
committerGitHub <[email protected]>2024-03-05 23:37:14 +0000
commit2a78c9c5e428549fbb40b57b1bd78cf7746e37e3 (patch)
treeb1d376be7ccac939b94bfcbb91b691c161e49db2
parent01d5568b20408a7f72fb53095e2e146f0c39672a (diff)
downloadcaddy-2a78c9c5e428549fbb40b57b1bd78cf7746e37e3.tar.gz
caddy-2a78c9c5e428549fbb40b57b1bd78cf7746e37e3.zip
httpcaddyfile: Allow nameless regexp placeholder shorthand (#6113)
Co-authored-by: Matt Holt <[email protected]>
-rw-r--r--caddyconfig/httpcaddyfile/shorthands.go2
-rw-r--r--caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest19
2 files changed, 20 insertions, 1 deletions
diff --git a/caddyconfig/httpcaddyfile/shorthands.go b/caddyconfig/httpcaddyfile/shorthands.go
index 75795ae61..5855d127c 100644
--- a/caddyconfig/httpcaddyfile/shorthands.go
+++ b/caddyconfig/httpcaddyfile/shorthands.go
@@ -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}"},
diff --git a/caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest b/caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest
index d5c35b3c3..30bc2c128 100644
--- a/caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest
+++ b/caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest
@@ -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": {
@@ -25,6 +29,21 @@ respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
{
"handle": [
{
+ "body": "{http.regexp.1}",
+ "handler": "static_response"
+ }
+ ],
+ "match": [
+ {
+ "path_regexp": {
+ "pattern": "^/foo(.*)$"
+ }
+ }
+ ]
+ },
+ {
+ "handle": [
+ {
"body": "{http.request.header.content-type} {http.request.host.labels.0} {http.request.uri.query.p} {http.request.uri.path.0} {http.regexp.name.0}",
"handler": "static_response"
}