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

fix: should break the loop when connection has closed #18

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 1 deletion ws_reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ func (w *WSReverseProxy) ServeHTTP(ctx context.Context, c *app.RequestContext) {

var ce *websocket.CloseError
var hzce *hzws.CloseError
if !errors.As(err, &ce) || !errors.As(err, &hzce) {
if !errors.As(err, &ce) && !errors.As(err, &hzce) {
hlog.CtxErrorf(ctx, errMsg, err)
continue
}

break
}
}); err != nil {
hlog.CtxErrorf(ctx, "can not upgrade to websocket: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions ws_reverse_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestProxy(t *testing.T) {

// proxy server
ps := server.Default(server.WithHostPorts(":7777"))
ps.NoHijackConnPool = true
ps.GET("/proxy", proxy.ServeHTTP)
go ps.Spin()

Expand All @@ -63,6 +64,7 @@ func TestProxy(t *testing.T) {
go func() {
// backend server
bs := server.Default()
bs.NoHijackConnPool = true
bs.GET("/", func(ctx context.Context, c *app.RequestContext) {
// Don't upgrade if original host header isn't preserved
host := string(c.Host())
Expand Down
Loading