modify: header option

This commit is contained in:
misu 2018-01-18 01:41:59 +09:00
parent cdedf21e58
commit 8a8329be68
1 changed files with 19 additions and 4 deletions

View File

@ -7,6 +7,7 @@ package websocket
import ( import (
"bufio" "bufio"
"errors" "errors"
"fmt"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -142,14 +143,25 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
subprotocol := u.selectSubprotocol(r, responseHeader) subprotocol := u.selectSubprotocol(r, responseHeader)
// Negotiate PMCE // Negotiate PMCE
var compress bool var (
compress bool
contextTakeover bool
)
if u.EnableCompression { if u.EnableCompression {
for _, ext := range parseExtensions(r.Header) { for _, ext := range parseExtensions(r.Header) {
if ext[""] != "permessage-deflate" { // map[string]string{"":"permessage-deflate", "client_max_window_bits":""}
// context-takeoverをclient_max_window_bitsから判定する
fmt.Printf("%#v\n", ext)
if ext[""] == "permessage-deflate" {
compress = true
continue
}
if _, ok := ext["client_max_window_bits"]; ok {
// Todo: validation. window size level only allow 15.
contextTakeover = true
continue continue
} }
compress = true
break
} }
} }
@ -177,6 +189,9 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
c.subprotocol = subprotocol c.subprotocol = subprotocol
if compress { if compress {
if contextTakeover {
}
c.newCompressionWriter = compressNoContextTakeover c.newCompressionWriter = compressNoContextTakeover
c.newDecompressionReader = decompressNoContextTakeover c.newDecompressionReader = decompressNoContextTakeover
} }