Commit 1d47e590 authored by Matthew Holt's avatar Matthew Holt

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

parent 280ba9db
...@@ -41,6 +41,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) { ...@@ -41,6 +41,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
for c.Next() { for c.Next() {
upstream := &staticUpstream{ upstream := &staticUpstream{
from: "", from: "",
proxyHeaders: make(http.Header),
Hosts: nil, Hosts: nil,
Policy: &Random{}, Policy: &Random{},
FailTimeout: 10 * time.Second, FailTimeout: 10 * time.Second,
...@@ -159,14 +160,8 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error { ...@@ -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":
......
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