Commit ccd3e55b authored by Austin's avatar Austin

changes as noted in PR

parent 56ec7b98
...@@ -16,8 +16,6 @@ import ( ...@@ -16,8 +16,6 @@ import (
"time" "time"
) )
const HTTPSwitchingProtocols = 101
// onExitFlushLoop is a callback set by tests to detect the state of the // onExitFlushLoop is a callback set by tests to detect the state of the
// flushLoop() goroutine. // flushLoop() goroutine.
var onExitFlushLoop func() var onExitFlushLoop func()
...@@ -149,13 +147,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr ...@@ -149,13 +147,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
} }
defer res.Body.Close() defer res.Body.Close()
for _, h := range hopHeaders { if res.StatusCode == http.StatusSwitchingProtocols && outreq.Header.Get("Upgrade") == "websocket" {
res.Header.Del(h)
}
copyHeader(rw.Header(), res.Header)
if res.StatusCode == HTTPSwitchingProtocols && outreq.Header.Get("Upgrade") == "websocket" {
hj, ok := rw.(http.Hijacker) hj, ok := rw.(http.Hijacker)
if !ok { if !ok {
return nil return nil
...@@ -182,6 +174,12 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr ...@@ -182,6 +174,12 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
io.Copy(conn, backendConn) // read tcp stream from backend. io.Copy(conn, backendConn) // read tcp stream from backend.
conn.Close() conn.Close()
} else { } else {
for _, h := range hopHeaders {
res.Header.Del(h)
}
copyHeader(rw.Header(), res.Header)
rw.WriteHeader(res.StatusCode) rw.WriteHeader(res.StatusCode)
p.copyResponse(rw, res.Body) p.copyResponse(rw, res.Body)
} }
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
var ( var (
supportedPolicies map[string]func() Policy = make(map[string]func() Policy) supportedPolicies map[string]func() Policy = make(map[string]func() Policy)
proxyHeaders http.Header proxyHeaders http.Header = make(http.Header)
) )
type staticUpstream struct { type staticUpstream struct {
...@@ -100,10 +100,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) { ...@@ -100,10 +100,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
if !c.Args(&header, &value) { if !c.Args(&header, &value) {
return upstreams, c.ArgErr() return upstreams, c.ArgErr()
} }
addProxyHeader(header, value) proxyHeaders.Add(header, value)
case "websocket": case "websocket":
addProxyHeader("Connection", "{>Connection}") proxyHeaders.Add("Connection", "{>Connection}")
addProxyHeader("Upgrade", "{>Upgrade}") proxyHeaders.Add("Upgrade", "{>Upgrade}")
} }
} }
...@@ -153,14 +153,6 @@ func RegisterPolicy(name string, policy func() Policy) { ...@@ -153,14 +153,6 @@ func RegisterPolicy(name string, policy func() Policy) {
supportedPolicies[name] = policy supportedPolicies[name] = policy
} }
// AddProxyHeader adds a proxy header.
func addProxyHeader(header, value string) {
if proxyHeaders == nil {
proxyHeaders = make(map[string][]string)
}
proxyHeaders.Add(header, value)
}
func (u *staticUpstream) From() string { func (u *staticUpstream) From() string {
return u.from return u.from
} }
......
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