Matthew Holt
3 years ago
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with
21 additions and
0 deletions
-
modules/caddyhttp/map/map.go
-
modules/caddyhttp/map/map_test.go
|
|
@ -145,6 +145,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt |
|
|
|
return string(result), true |
|
|
|
} |
|
|
|
if input == m.Input { |
|
|
|
if outputStr, ok := output.(string); ok { |
|
|
|
// NOTE: if the output has a placeholder that has the same key as the input, this is infinite recursion
|
|
|
|
return repl.ReplaceAll(outputStr, ""), true |
|
|
|
} |
|
|
|
return output, true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -82,6 +82,22 @@ func TestHandler(t *testing.T) { |
|
|
|
"output": "3", |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
reqURI: "/foo", |
|
|
|
handler: Handler{ |
|
|
|
Source: "{http.request.uri.path}", |
|
|
|
Destinations: []string{"{output}"}, |
|
|
|
Mappings: []Mapping{ |
|
|
|
{ |
|
|
|
Input: "/foo", |
|
|
|
Outputs: []interface{}{"{testvar}"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
expect: map[string]interface{}{ |
|
|
|
"output": "testing", |
|
|
|
}, |
|
|
|
}, |
|
|
|
} { |
|
|
|
if err := tc.handler.Provision(caddy.Context{}); err != nil { |
|
|
|
t.Fatalf("Test %d: Provisioning handler: %v", i, err) |
|
|
@ -92,6 +108,7 @@ func TestHandler(t *testing.T) { |
|
|
|
t.Fatalf("Test %d: Creating request: %v", i, err) |
|
|
|
} |
|
|
|
repl := caddyhttp.NewTestReplacer(req) |
|
|
|
repl.Set("testvar", "testing") |
|
|
|
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) |
|
|
|
req = req.WithContext(ctx) |
|
|
|
|
|
|
|