Skip to content

Commit 9f03e74

Browse files
committed
1 parent 3419f33 commit 9f03e74

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

rc.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/http/httptest"
1010
"os"
11+
"strings"
1112
"syscall"
1213
"time"
1314

@@ -88,7 +89,7 @@ func newCacheMw(c Cacher, opts ...Option) *cacheMw {
8889
func (m *cacheMw) Handler(next http.Handler) http.Handler {
8990
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
9091
// rc does not support websocket.
91-
if req.Header.Get("Connection") == "Upgrade" && req.Header.Get("Upgrade") == "websocket" {
92+
if strings.ToLower(req.Header.Get("Connection")) == "upgrade" && strings.ToLower(req.Header.Get("Upgrade")) == "websocket" {
9293
next.ServeHTTP(w, req)
9394
return
9495
}

rc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestRC(t *testing.T) {
5454
}, 1},
5555
{"does not support websocket", testutil.NewAllCache(t), []*http.Request{
5656
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
57-
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
58-
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
57+
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "UPGRADE": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
58+
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"WEBSOCKET"}}, URL: testutil.MustParseURL("http://example.com/1")},
5959
}, []*http.Response{
6060
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":1}`)},
6161
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":2}`)},

0 commit comments

Comments
 (0)