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 cafd7296f4.

* Revert "test added"

This reverts commit 3a76cc7b0b.

* Revert "using Matcher methods"

This reverts commit cc34337b8e.

* tests added
This commit is contained in:
Rajat Jain 2021-03-11 02:52:33 +05:30 committed by GitHub
parent 51f35ba03f
commit 802f80c382
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -19,7 +19,7 @@ func TestMap(t *testing.T) {
map {http.request.method} {dest-1} {dest-2} { map {http.request.method} {dest-1} {dest-2} {
default unknown1 unknown2 default unknown1 unknown2
~G.T get-called ~G(.)(.) G${1}${2}-called
POST post-called foobar POST post-called foobar
} }
@ -30,7 +30,7 @@ func TestMap(t *testing.T) {
`, "caddyfile") `, "caddyfile")
// act and assert // act and assert
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called unknown2") tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost GET-called unknown2")
tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar") tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar")
} }

View file

@ -136,6 +136,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
if output := m.Outputs[destIdx]; output == nil { if output := m.Outputs[destIdx]; output == nil {
continue continue
} else { } else {
output = m.re.ReplaceAllString(input, m.Outputs[destIdx].(string))
return output, true return output, true
} }
} }