summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/replacer.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-10 21:07:02 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-10 21:07:02 -0600
commit8ae0d6a509fd1b871457cf742369af04346933a8 (patch)
tree9a0b977e5f36acc6f06737ff34b1f21d608ada6f /modules/caddyhttp/replacer.go
parent48b5a803208548d143b7ead9b6fc9b524cd0e031 (diff)
caddyhttp: Implement better HTTP matchers including regexp; add tests
Diffstat (limited to 'modules/caddyhttp/replacer.go')
-rw-r--r--modules/caddyhttp/replacer.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index 947de09..644cfc1 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -8,7 +8,9 @@ import (
)
// Replacer can replace values in strings based
-// on a request and/or response writer.
+// on a request and/or response writer. The zero
+// Replacer is not valid; it must be initialized
+// within this package.
type Replacer struct {
req *http.Request
resp http.ResponseWriter
@@ -75,18 +77,17 @@ func (r *Replacer) defaults() map[string]string {
}(),
}
+ // TODO: why should header fields, cookies, and query params get special treatment like this?
+ // maybe they should be scoped by words like "request.header." just like everything else.
for field, vals := range r.req.Header {
m[">"+strings.ToLower(field)] = strings.Join(vals, ",")
}
-
for field, vals := range r.resp.Header() {
m["<"+strings.ToLower(field)] = strings.Join(vals, ",")
}
-
for _, cookie := range r.req.Cookies() {
m["~"+cookie.Name] = cookie.Value
}
-
for param, vals := range r.req.URL.Query() {
m["?"+param] = strings.Join(vals, ",")
}