mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
map: Accept regex substitution in outputs (#3991)
* Replace placeholders with regex groups * using Matcher methods * test added * linting fix * Revert "linting fix" This reverts commitcafd7296f4
. * Revert "test added" This reverts commit3a76cc7b0b
. * Revert "using Matcher methods" This reverts commitcc34337b8e
. * tests added
This commit is contained in:
parent
51f35ba03f
commit
802f80c382
2 changed files with 3 additions and 2 deletions
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue