@marcel91200 / caddy Mirror · read-only / commits / 2a78c9c5
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 15:45 UTC

httpcaddyfile: Allow nameless regexp placeholder shorthand (#6113)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Francis Lavoie committed Mar 5, 2024 at 18:37 UTC 2a78c9c5e428549fbb40b57b1bd78cf7746e37e3
2 files changed +20 -1
caddyconfig/httpcaddyfile/shorthands.go
+1 -1
@@ -33,7 +33,7 @@ func NewShorthandReplacer() ShorthandReplacer {
33 {regexp.MustCompile(`{path\.([\w-]*)}`), "{http.request.uri.path.$1}"},
34 {regexp.MustCompile(`{file\.([\w-]*)}`), "{http.request.uri.path.file.$1}"},
35 {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}"},
37 {regexp.MustCompile(`{vars\.([\w-]*)}`), "{http.vars.$1}"},
38 {regexp.MustCompile(`{rp\.([\w-\.]*)}`), "{http.reverse_proxy.$1}"},
39 {regexp.MustCompile(`{err\.([\w-\.]*)}`), "{http.error.$1}"},
caddytest/integration/caddyfile_adapt/shorthand_parameterized_placeholders.caddyfiletest
+19
@@ -1,5 +1,9 @@
1 localhost:80
2 +
3 respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
4 +
5 +@match path_regexp ^/foo(.*)$
6 +respond @match "{re.1}"
7 ----------
8 {
9 "apps": {
@@ -22,6 +26,21 @@ respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}"
26 {
27 "handler": "subroute",
28 "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 + },
44 {
45 "handle": [
46 {