Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc does not support websocket. #74

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ 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" {
next.ServeHTTP(w, req)
return
}
now := time.Now()

// Copy the request so that it is not affected by the next handler.
Expand Down
9 changes: 9 additions & 0 deletions rc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func TestRC(t *testing.T) {
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":3}`)},
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}, "X-Cache": []string{"HIT"}}, Body: testutil.NewBody(`{"count":2}`)},
}, 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")},
}, []*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}`)},
{StatusCode: http.StatusOK, Header: http.Header{"Cache-Control": []string{"max-age=60"}, "Content-Type": []string{"application/json"}}, Body: testutil.NewBody(`{"count":3}`)},
}, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
22 changes: 12 additions & 10 deletions testdata/go_test.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ go 1.21.5

require (
github.com/google/go-cmp v0.6.0
github.com/k1LoW/httpstub v0.12.0
github.com/k1LoW/httpstub v0.16.4
)

require (
github.com/getkin/kin-openapi v0.115.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/invopop/yaml v0.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/minio/pkg v1.6.5 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/minio/pkg v1.7.5 // indirect
github.com/pb33f/libopenapi v0.16.7 // indirect
github.com/pb33f/libopenapi-validator v0.0.56 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/sync v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading