summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Dyke <[email protected]>2016-06-14 19:03:30 +0100
committerMatt Holt <[email protected]>2016-06-14 12:03:30 -0600
commitb14baf7e206c4fa6b37eee6f4be8f0e9af390899 (patch)
treeeea227cdbb3cb22cf2126405330aecec0f60a607
parent2b06edccd355b7b692905968a305712f7d350c25 (diff)
downloadcaddy-b14baf7e206c4fa6b37eee6f4be8f0e9af390899.tar.gz
caddy-b14baf7e206c4fa6b37eee6f4be8f0e9af390899.zip
Add proxy preset: transparent (#881)
* Add reverse_proxy preset * Update to 'transparent' preset instead of 'reverse_proxy'
-rw-r--r--caddyhttp/proxy/upstream.go4
-rw-r--r--caddyhttp/proxy/upstream_test.go40
2 files changed, 44 insertions, 0 deletions
diff --git a/caddyhttp/proxy/upstream.go b/caddyhttp/proxy/upstream.go
index 4dc78e820..00d23e319 100644
--- a/caddyhttp/proxy/upstream.go
+++ b/caddyhttp/proxy/upstream.go
@@ -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}")
diff --git a/caddyhttp/proxy/upstream_test.go b/caddyhttp/proxy/upstream_test.go
index 9d38b785f..0378475f2 100644
--- a/caddyhttp/proxy/upstream_test.go
+++ b/caddyhttp/proxy/upstream_test.go
@@ -1,8 +1,11 @@
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)
+ }
+ }
+ }
+}