Skip to content

Commit 9c8669f

Browse files
authored
fix: Websocket requests fail if case of value in Connection header and case of key in Upgrade header do not match (#3563)
When a client sends a request to upgrade to a Websocket connection and presents the value of the header `Connection` in lower-case then Skipper fails to upgrade the request. This change fixes the issue by using a function to read the header that is case insensitive. The bug was likely introduced in #3553. Signed-off-by: Markus Meyer <m.meyer@mytaxi.com>
1 parent 485d0ef commit 9c8669f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

proxy/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func isUpgradeRequest(req *http.Request) bool {
3232
func getUpgradeRequest(req *http.Request) string {
3333
for _, h := range req.Header[http.CanonicalHeaderKey("Connection")] {
3434
if strings.Contains(strings.ToLower(h), "upgrade") {
35-
return strings.Join(req.Header[h], " ")
35+
return strings.Join(req.Header.Values(h), " ")
3636
}
3737
}
3838
return ""

proxy/upgrade_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ func TestValidGetUpgradeRequest(t *testing.T) {
8787

8888
}
8989

90+
func TestValidGetUpgradeRequestCaseInsensitivity(t *testing.T) {
91+
req, prot := getValidUpgradeRequest()
92+
req.Header.Set("Connection", "uPgRaDe")
93+
if !isUpgradeRequest(req) {
94+
t.Errorf("Request has an upgrade header, but isUpgradeRequest returned false for %+v", req)
95+
}
96+
gotProt := getUpgradeRequest(req)
97+
if gotProt != prot {
98+
t.Errorf("%s != %s for %+v", gotProt, prot, req)
99+
}
100+
101+
}
102+
90103
func TestServeHTTP(t *testing.T) {
91104
for _, ti := range []struct {
92105
msg string

0 commit comments

Comments
 (0)