Skip to content

Commit

Permalink
fix: should break the loop when connection has closed (#18)
Browse files Browse the repository at this point in the history
* fix: should break the loop

* chore: modify unit test

---------

Co-authored-by: kinggo <[email protected]>
  • Loading branch information
whxaxes and li-jin-gou authored Jan 4, 2024
1 parent f728214 commit 3059929
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 3059929

Please sign in to comment.