Commit b14baf7e authored by David Dyke's avatar David Dyke Committed by Matt Holt

Add proxy preset: transparent (#881)

* Add reverse_proxy preset

* Update to 'transparent' preset instead of 'reverse_proxy'
parent 2b06edcc
......@@ -260,6 +260,10 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error {
return c.ArgErr()
}
u.downstreamHeaders.Add(header, value)
case "transparent":
u.upstreamHeaders.Add("Host", "{host}")
u.upstreamHeaders.Add("X-Real-IP", "{remote}")
u.upstreamHeaders.Add("X-Forwarded-Proto", "{scheme}")
case "websocket":
u.upstreamHeaders.Add("Connection", "{>Connection}")
u.upstreamHeaders.Add("Upgrade", "{>Upgrade}")
......
package proxy
import (
"strings"
"testing"
"time"
"github.com/mholt/caddy/caddyfile"
)
func TestNewHost(t *testing.T) {
......@@ -133,3 +136,40 @@ func TestAllowedPaths(t *testing.T) {
}
}
}
func TestParseBlock(t *testing.T) {
tests := []struct {
config string
}{
// Test #1: transparent preset
{"proxy / localhost:8080 {\n transparent \n}"},
// Test #2: transparent preset with another param
{"proxy / localhost:8080 {\n transparent \nproxy_header X-Test Tester \n}"},
// Test #3: transparent preset on multiple sites
{"proxy / localhost:8080 {\n transparent \n} \nproxy /api localhost:8081 { \ntransparent \n}"},
}
for i, test := range tests {
upstreams, err := NewStaticUpstreams(caddyfile.NewDispenser("Testfile", strings.NewReader(test.config)))
if err != nil {
t.Error("Expected no error. Got:", err.Error())
}
for _, upstream := range upstreams {
headers := upstream.Select().UpstreamHeaders
if _, ok := headers["Host"]; !ok {
t.Errorf("Test %d: Could not find the Host header", i+1)
}
if _, ok := headers["X-Real-Ip"]; !ok {
t.Errorf("Test %d: Could not find the X-Real-Ip header", i+1)
}
if _, ok := headers["X-Forwarded-Proto"]; !ok {
t.Errorf("Test %d: Could not find the X-Forwarded-Proto header", i+1)
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment