From ea7e4b4024f34fd53f8b8f7b5effb353b36cf8e8 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 11 May 2020 18:50:49 -0400 Subject: httpcaddyfile: Shorthands for parameterized placeholders (#3305) * httpcaddyfile: Add shorthands for parameterized placeholders httpcaddyfile: Now with regexp instead httpcaddyfile: Allow dashes, gofmt httpcaddyfile: Compile regexp only once httpcaddyfile: Cleanup struct httpcaddyfile: Optimize the replacers, pull out of the loop httpcaddyfile: Add `{port}` shorthand * httpcaddyfile: Switch `r.` to `re.` --- caddytest/integration/caddyfile_adapt_test.go | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'caddytest/integration') diff --git a/caddytest/integration/caddyfile_adapt_test.go b/caddytest/integration/caddyfile_adapt_test.go index 98c81da..280e22e 100644 --- a/caddytest/integration/caddyfile_adapt_test.go +++ b/caddytest/integration/caddyfile_adapt_test.go @@ -539,3 +539,49 @@ func TestLogRollDays(t *testing.T) { } }`) } + +func TestShorthandParameterizedPlaceholders(t *testing.T) { + caddytest.AssertAdapt(t, ` + localhost:80 + respond * "{header.content-type} {labels.0} {query.p} {path.0} {re.name.0}" + `, "caddyfile", `{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":80" + ], + "routes": [ + { + "match": [ + { + "host": [ + "localhost" + ] + } + ], + "handle": [ + { + "handler": "subroute", + "routes": [ + { + "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" + } + ] + } + ] + } + ], + "terminal": true + } + ] + } + } + } + } +}`) +} -- cgit v1.2.3