mirror of https://github.com/gorilla/websocket.git
fixed: header case sensivity
This commit is contained in:
parent
a6f041ac33
commit
aa2b19d516
|
@ -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")
|
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")
|
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")
|
return u.returnError(w, r, http.StatusBadRequest, "websocket: upgrade != websocket")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
util.go
15
util.go
|
@ -9,23 +9,8 @@ import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"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")
|
var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
|
||||||
|
|
||||||
func computeAcceptKey(challengeKey string) string {
|
func computeAcceptKey(challengeKey string) string {
|
||||||
|
|
Loading…
Reference in New Issue