0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

proxy: Make headers when upstream is created; avoid potential nil ptr deref

This commit is contained in:
Matthew Holt 2015-11-17 10:18:13 -07:00
parent 280ba9db85
commit 1d47e590e5

View file

@ -40,11 +40,12 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
var upstreams []Upstream var upstreams []Upstream
for c.Next() { for c.Next() {
upstream := &staticUpstream{ upstream := &staticUpstream{
from: "", from: "",
Hosts: nil, proxyHeaders: make(http.Header),
Policy: &Random{}, Hosts: nil,
FailTimeout: 10 * time.Second, Policy: &Random{},
MaxFails: 1, FailTimeout: 10 * time.Second,
MaxFails: 1,
} }
if !c.Args(&upstream.from) { if !c.Args(&upstream.from) {
@ -159,14 +160,8 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error {
if !c.Args(&header, &value) { if !c.Args(&header, &value) {
return c.ArgErr() return c.ArgErr()
} }
if u.proxyHeaders == nil {
u.proxyHeaders = make(http.Header)
}
u.proxyHeaders.Add(header, value) u.proxyHeaders.Add(header, value)
case "websocket": case "websocket":
if u.proxyHeaders == nil {
u.proxyHeaders = make(http.Header)
}
u.proxyHeaders.Add("Connection", "{>Connection}") u.proxyHeaders.Add("Connection", "{>Connection}")
u.proxyHeaders.Add("Upgrade", "{>Upgrade}") u.proxyHeaders.Add("Upgrade", "{>Upgrade}")
case "without": case "without":