mirror of https://github.com/gorilla/websocket.git
add: context-takeover option to client
This commit is contained in:
parent
ad97036825
commit
dfe35b789b
29
client.go
29
client.go
|
@ -78,6 +78,11 @@ type Dialer struct {
|
||||||
// takeover" modes are supported.
|
// takeover" modes are supported.
|
||||||
EnableCompression bool
|
EnableCompression bool
|
||||||
|
|
||||||
|
// EnableContextTakeover specifies specifies if the client should attempt to negotiate
|
||||||
|
// per message compression with context-takeover (RFC 7692).
|
||||||
|
// but window bits is allowed only 15, because go's flate library support 15 bits only.
|
||||||
|
EnableContextTakeover bool
|
||||||
|
|
||||||
// Jar specifies the cookie jar.
|
// Jar specifies the cookie jar.
|
||||||
// If Jar is nil, cookies are not sent in requests and ignored
|
// If Jar is nil, cookies are not sent in requests and ignored
|
||||||
// in responses.
|
// in responses.
|
||||||
|
@ -196,7 +201,10 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.EnableCompression {
|
switch {
|
||||||
|
case d.EnableCompression && d.EnableContextTakeover:
|
||||||
|
req.Header.Set("Sec-Websocket-Extensions", "permessage-deflate; server_max_window_bits=15; client_max_window_bits=15")
|
||||||
|
case d.EnableCompression:
|
||||||
req.Header.Set("Sec-Websocket-Extensions", "permessage-deflate; server_no_context_takeover; client_no_context_takeover")
|
req.Header.Set("Sec-Websocket-Extensions", "permessage-deflate; server_no_context_takeover; client_no_context_takeover")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,13 +315,20 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
|
||||||
if ext[""] != "permessage-deflate" {
|
if ext[""] != "permessage-deflate" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, snct := ext["server_no_context_takeover"]
|
|
||||||
_, cnct := ext["client_no_context_takeover"]
|
_, cmwb := ext["client_max_window_bits"]
|
||||||
if !snct || !cnct {
|
_, smwb := ext["server_max_window_bits"]
|
||||||
return nil, resp, errInvalidCompression
|
|
||||||
|
switch {
|
||||||
|
case cmwb && smwb:
|
||||||
|
conn.contextTakeover = true
|
||||||
|
conn.newCompressionWriter = compressContextTakeover
|
||||||
|
conn.newDecompressionReader = decompressContextTakeover
|
||||||
|
default:
|
||||||
|
conn.newCompressionWriter = compressNoContextTakeover
|
||||||
|
conn.newDecompressionReader = decompressNoContextTakeover
|
||||||
}
|
}
|
||||||
conn.newCompressionWriter = compressNoContextTakeover
|
|
||||||
conn.newDecompressionReader = decompressNoContextTakeover
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue