Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jun 13, 2024
1 parent 3419f33 commit 9f03e74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -88,7 +89,7 @@ func newCacheMw(c Cacher, opts ...Option) *cacheMw {
func (m *cacheMw) Handler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// rc does not support websocket.
if req.Header.Get("Connection") == "Upgrade" && req.Header.Get("Upgrade") == "websocket" {
if strings.ToLower(req.Header.Get("Connection")) == "upgrade" && strings.ToLower(req.Header.Get("Upgrade")) == "websocket" {
next.ServeHTTP(w, req)
return
}
Expand Down
4 changes: 2 additions & 2 deletions rc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestRC(t *testing.T) {
}, 1},
{"does not support websocket", testutil.NewAllCache(t), []*http.Request{
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "UPGRADE": []string{"websocket"}}, URL: testutil.MustParseURL("http://example.com/1")},
{Method: http.MethodGet, Header: http.Header{"Connection": []string{"Upgrade"}, "Upgrade": []string{"WEBSOCKET"}}, URL: testutil.MustParseURL("http://example.com/1")},
}, []*http.Response{
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":1}`)},
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":2}`)},
Expand Down

0 comments on commit 9f03e74

Please sign in to comment.