mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
websocket directive, upgrade comparison
This commit is contained in:
parent
2d6ff40649
commit
56ec7b9887
2 changed files with 19 additions and 8 deletions
|
@ -16,7 +16,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HTTPSwitchProtocols = 101
|
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.
|
||||||
|
@ -155,7 +155,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
|
||||||
|
|
||||||
copyHeader(rw.Header(), res.Header)
|
copyHeader(rw.Header(), res.Header)
|
||||||
|
|
||||||
if res.StatusCode == HTTPSwitchProtocols {
|
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
|
||||||
|
|
|
@ -12,7 +12,10 @@ import (
|
||||||
"github.com/mholt/caddy/config/parse"
|
"github.com/mholt/caddy/config/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedPolicies map[string]func() Policy = make(map[string]func() Policy)
|
var (
|
||||||
|
supportedPolicies map[string]func() Policy = make(map[string]func() Policy)
|
||||||
|
proxyHeaders http.Header
|
||||||
|
)
|
||||||
|
|
||||||
type staticUpstream struct {
|
type staticUpstream struct {
|
||||||
from string
|
from string
|
||||||
|
@ -40,7 +43,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
|
||||||
FailTimeout: 10 * time.Second,
|
FailTimeout: 10 * time.Second,
|
||||||
MaxFails: 1,
|
MaxFails: 1,
|
||||||
}
|
}
|
||||||
var proxyHeaders http.Header
|
|
||||||
if !c.Args(&upstream.from) {
|
if !c.Args(&upstream.from) {
|
||||||
return upstreams, c.ArgErr()
|
return upstreams, c.ArgErr()
|
||||||
}
|
}
|
||||||
|
@ -97,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()
|
||||||
}
|
}
|
||||||
if proxyHeaders == nil {
|
addProxyHeader(header, value)
|
||||||
proxyHeaders = make(map[string][]string)
|
case "websocket":
|
||||||
}
|
addProxyHeader("Connection", "{>Connection}")
|
||||||
proxyHeaders.Add(header, value)
|
addProxyHeader("Upgrade", "{>Upgrade}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +153,14 @@ 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue