fixed: header case sensivity

This commit is contained in:
Mário Freitas 2014-11-17 20:07:46 +09:00
parent a6f041ac33
commit aa2b19d516
2 changed files with 2 additions and 17 deletions

View File

@ -102,11 +102,11 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
return u.returnError(w, r, http.StatusBadRequest, "websocket: version != 13")
}
if !tokenListContainsValue(r.Header, "Connection", "upgrade") {
if strings.ToLower(r.Header.Get("Connection")) != "upgrade"
return u.returnError(w, r, http.StatusBadRequest, "websocket: connection header != upgrade")
}
if !tokenListContainsValue(r.Header, "Upgrade", "websocket") {
if strings.ToLower(r.Header.Get("Upgrade")) != "websocket"
return u.returnError(w, r, http.StatusBadRequest, "websocket: upgrade != websocket")
}

15
util.go
View File

@ -9,23 +9,8 @@ import (
"crypto/sha1"
"encoding/base64"
"io"
"net/http"
"strings"
)
// tokenListContainsValue returns true if the 1#token header with the given
// name contains token.
func tokenListContainsValue(header http.Header, name string, value string) bool {
for _, v := range header[name] {
for _, s := range strings.Split(v, ",") {
if strings.EqualFold(value, strings.TrimSpace(s)) {
return true
}
}
}
return false
}
var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
func computeAcceptKey(challengeKey string) string {