From 1d47e590e5ffda4b02e639b1f8b54498e0a800fe Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 17 Nov 2015 10:18:13 -0700 Subject: [PATCH] proxy: Make headers when upstream is created; avoid potential nil ptr deref --- middleware/proxy/upstream.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/middleware/proxy/upstream.go b/middleware/proxy/upstream.go index 5e9152e4..28dbb665 100644 --- a/middleware/proxy/upstream.go +++ b/middleware/proxy/upstream.go @@ -40,11 +40,12 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) { var upstreams []Upstream for c.Next() { upstream := &staticUpstream{ - from: "", - Hosts: nil, - Policy: &Random{}, - FailTimeout: 10 * time.Second, - MaxFails: 1, + from: "", + proxyHeaders: make(http.Header), + Hosts: nil, + Policy: &Random{}, + FailTimeout: 10 * time.Second, + MaxFails: 1, } if !c.Args(&upstream.from) { @@ -159,14 +160,8 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error { if !c.Args(&header, &value) { return c.ArgErr() } - if u.proxyHeaders == nil { - u.proxyHeaders = make(http.Header) - } u.proxyHeaders.Add(header, value) case "websocket": - if u.proxyHeaders == nil { - u.proxyHeaders = make(http.Header) - } u.proxyHeaders.Add("Connection", "{>Connection}") u.proxyHeaders.Add("Upgrade", "{>Upgrade}") case "without":