mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Add proxy preset: transparent (#881)
* Add reverse_proxy preset * Update to 'transparent' preset instead of 'reverse_proxy'
This commit is contained in:
parent
2b06edccd3
commit
b14baf7e20
2 changed files with 44 additions and 0 deletions
|
@ -260,6 +260,10 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error {
|
||||||
return c.ArgErr()
|
return c.ArgErr()
|
||||||
}
|
}
|
||||||
u.downstreamHeaders.Add(header, value)
|
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":
|
case "websocket":
|
||||||
u.upstreamHeaders.Add("Connection", "{>Connection}")
|
u.upstreamHeaders.Add("Connection", "{>Connection}")
|
||||||
u.upstreamHeaders.Add("Upgrade", "{>Upgrade}")
|
u.upstreamHeaders.Add("Upgrade", "{>Upgrade}")
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy/caddyfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewHost(t *testing.T) {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue