Commit 4efdb099 authored by Simao Gomes Viana's avatar Simao Gomes Viana 🛠

injection: add support for multiple values in Upgrade and Connection

This is necessary for websocket as the server might, for example, add
keep-alive to Connection.
parent 7c6e2826
......@@ -375,8 +375,32 @@ func CreateInjectedWriter(
}
func (m Middleware) IsWebSocket(r *http.Request) bool {
return strings.EqualFold(r.Header.Get("connection"), "upgrade") &&
strings.EqualFold(r.Header.Get("upgrade"), "websocket")
connectionValue := r.Header.Get("connection")
connectionValues := strings.Split(connectionValue, ",")
connectionValueMatches := false
for _, connectionElem := range connectionValues {
if strings.EqualFold(strings.TrimSpace(connectionElem), "upgrade") {
connectionValueMatches = true
break
}
}
if !connectionValueMatches {
return false
}
upgradeValue := r.Header.Get("upgrade")
upgradeValues := strings.Split(upgradeValue, ",")
upgradeValueMatches := false
for _, upgradeElem := range upgradeValues {
if strings.EqualFold(strings.TrimSpace(upgradeElem), "websocket") {
upgradeValueMatches = true
}
}
if !upgradeValueMatches {
return false
}
return true
}
func (m Middleware) ShouldBypassForRequest(w http.ResponseWriter, r *http.Request) bool {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment