add: validation

This commit is contained in:
misu 2018-01-19 01:43:04 +09:00
parent 8a8329be68
commit 053a620207
1 changed files with 10 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"time" "time"
) )
@ -150,15 +151,21 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
if u.EnableCompression { if u.EnableCompression {
for _, ext := range parseExtensions(r.Header) { for _, ext := range parseExtensions(r.Header) {
// map[string]string{"":"permessage-deflate", "client_max_window_bits":""} // map[string]string{"":"permessage-deflate", "client_max_window_bits":""}
// context-takeoverをclient_max_window_bitsから判定する // detect context-takeover from client_max_window_bits
fmt.Printf("%#v\n", ext) fmt.Printf("%#v\n", ext)
if ext[""] == "permessage-deflate" { if ext[""] == "permessage-deflate" {
compress = true compress = true
continue continue
} }
if _, ok := ext["client_max_window_bits"]; ok { if level, ok := ext["client_max_window_bits"]; ok {
// Todo: validation. window size level only allow 15. l, err := strconv.Atoi(level)
if err != nil {
return nil, errors.New(err.Error())
}
if l != 15 {
return u.returnError(w, r, http.StatusBadRequest, "client_max_window_bits level only allow 15.")
}
contextTakeover = true contextTakeover = true
continue continue
} }