From c25938154127107ff3c36d9d9b6553b20da60b4f Mon Sep 17 00:00:00 2001 From: Max Heyer Date: Sat, 26 Jan 2019 00:36:36 +0100 Subject: [PATCH] Add header X-Forwarded-Port with placeholder {server_port} to preset proxy preset transparent --- caddyhttp/proxy/upstream.go | 1 + caddyhttp/proxy/upstream_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/caddyhttp/proxy/upstream.go b/caddyhttp/proxy/upstream.go index 033fbecfc..f9a78e62d 100644 --- a/caddyhttp/proxy/upstream.go +++ b/caddyhttp/proxy/upstream.go @@ -448,6 +448,7 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream, hasSrv bool) error { u.upstreamHeaders.Add("Host", "{host}") u.upstreamHeaders.Add("X-Real-IP", "{remote}") u.upstreamHeaders.Add("X-Forwarded-Proto", "{scheme}") + u.upstreamHeaders.Add("X-Forwarded-Port", "{server_port}") case "websocket": u.upstreamHeaders.Add("Connection", "{>Connection}") u.upstreamHeaders.Add("Upgrade", "{>Upgrade}") diff --git a/caddyhttp/proxy/upstream_test.go b/caddyhttp/proxy/upstream_test.go index 18c652303..1e7196f63 100644 --- a/caddyhttp/proxy/upstream_test.go +++ b/caddyhttp/proxy/upstream_test.go @@ -321,6 +321,10 @@ func TestParseBlockTransparent(t *testing.T) { if _, ok := headers["X-Forwarded-For"]; ok { t.Errorf("Test %d: Found unexpected X-Forwarded-For header", i+1) } + + if _, ok := headers["X-Forwarded-Port"]; !ok { + t.Errorf("Test %d: Could not find the X-Forwarded-Port header", i+1) + } } } }