summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-20 13:13:49 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-20 13:13:49 -0600
commit2f684e42d5b8b78fe688b2f7e31d54d2333c0701 (patch)
tree41274f40173b2029d589b06601862ef08c3b209f /modules/caddyhttp/reverseproxy
parentba29f9d41d7951bde07dc2e0d6a1471c40bb7145 (diff)
reverse_proxy/headers: Expose header replacement ability in Caddyfile
Adds header_up and header_down subdirectives to reverse_proxy
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r--modules/caddyhttp/reverseproxy/caddyfile.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go
index d8c63b4..83298d8 100644
--- a/modules/caddyhttp/reverseproxy/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/caddyfile.go
@@ -25,6 +25,7 @@ import (
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
"github.com/dustin/go-humanize"
)
@@ -67,6 +68,10 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
// unhealthy_status <status>
// unhealthy_latency <duration>
//
+// # header manipulation
+// header_up [+|-]<field> [<value|regexp> [<replacement>]]
+// header_down [+|-]<field> [<value|regexp> [<replacement>]]
+//
// # round trip
// transport <name> {
// ...
@@ -327,6 +332,46 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
h.HealthChecks.Passive.UnhealthyLatency = caddy.Duration(dur)
+ case "header_up":
+ if h.Headers == nil {
+ h.Headers = new(headers.Handler)
+ }
+ if h.Headers.Request == nil {
+ h.Headers.Request = new(headers.HeaderOps)
+ }
+ args := d.RemainingArgs()
+ switch len(args) {
+ case 1:
+ headers.CaddyfileHeaderOp(h.Headers.Request, args[0], "", "")
+ case 2:
+ headers.CaddyfileHeaderOp(h.Headers.Request, args[0], args[1], "")
+ case 3:
+ headers.CaddyfileHeaderOp(h.Headers.Request, args[0], args[1], args[2])
+ default:
+ return d.ArgErr()
+ }
+
+ case "header_down":
+ if h.Headers == nil {
+ h.Headers = new(headers.Handler)
+ }
+ if h.Headers.Response == nil {
+ h.Headers.Response = &headers.RespHeaderOps{
+ HeaderOps: new(headers.HeaderOps),
+ }
+ }
+ args := d.RemainingArgs()
+ switch len(args) {
+ case 1:
+ headers.CaddyfileHeaderOp(h.Headers.Response.HeaderOps, args[0], "", "")
+ case 2:
+ headers.CaddyfileHeaderOp(h.Headers.Response.HeaderOps, args[0], args[1], "")
+ case 3:
+ headers.CaddyfileHeaderOp(h.Headers.Response.HeaderOps, args[0], args[1], args[2])
+ default:
+ return d.ArgErr()
+ }
+
case "transport":
if !d.NextArg() {
return d.ArgErr()