@marcel91200 / caddy Mirror · read-only / commits / 802f80c3
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 14, 05:15 UTC

map: Accept regex substitution in outputs (#3991)

* Replace placeholders with regex groups * using Matcher methods * test added * linting fix * Revert "linting fix" This reverts commit cafd7296f43639bbcd2601bea79a47f60763a200. * Revert "test added" This reverts commit 3a76cc7b0bc5dcef15ca5c8ec22efcd4067d484c. * Revert "using Matcher methods" This reverts commit cc34337b8ebb61d40ec343cee0fc225a694d3db6. * tests added

Rajat Jain committed Mar 11, 2021 at 02:52 UTC 802f80c3821940825ec278e1d9c153a321e956a9
2 files changed +3 -2
caddytest/integration/map_test.go
+2 -2
@@ -19,7 +19,7 @@ func TestMap(t *testing.T) {
19
20 map {http.request.method} {dest-1} {dest-2} {
21 default unknown1 unknown2
22 - ~G.T get-called
22 + ~G(.)(.) G${1}${2}-called
23 POST post-called foobar
24 }
25
@@ -30,7 +30,7 @@ func TestMap(t *testing.T) {
30 `, "caddyfile")
31
32 // act and assert
33 - tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called unknown2")
33 + tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost GET-called unknown2")
34 tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar")
35 }
36
modules/caddyhttp/map/map.go
+1
@@ -136,6 +136,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
136 if output := m.Outputs[destIdx]; output == nil {
137 continue
138 } else {
139 + output = m.re.ReplaceAllString(input, m.Outputs[destIdx].(string))
140 return output, true
141 }
142 }