diff options
author | Sergio VS <savsgio.engineer@gmail.com> | 2022-01-18 12:45:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 12:45:41 +0100 |
commit | 2aca3e82637860c90b8a3a2454ae8325706c1fd4 (patch) | |
tree | 1a853df6db916703df6578d0aaa49957f1c37f01 /server_test.go | |
parent | Updated dependencies (#1194) (diff) | |
download | fasthttp-2aca3e82637860c90b8a3a2454ae8325706c1fd4.tar.gz fasthttp-2aca3e82637860c90b8a3a2454ae8325706c1fd4.tar.bz2 fasthttp-2aca3e82637860c90b8a3a2454ae8325706c1fd4.zip |
fix(hijack): reset userValues after hijack handler execution (#1199)
* fix(hijack): reset userValues after hijack handler execution
* feat: add test
* fix: typo
* fix(test): race condition
Diffstat (limited to 'server_test.go')
-rw-r--r-- | server_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server_test.go b/server_test.go index ec2f656..47eb84d 100644 --- a/server_test.go +++ b/server_test.go @@ -2088,6 +2088,37 @@ func TestServeConnKeepRequestAndResponseUntilResetUserValues(t *testing.T) { } } +func TestServeConnHijackResetUserValues(t *testing.T) { + t.Parallel() + + rw := &readWriter{} + rw.r.WriteString("GET /foo HTTP/1.0\r\nConnection: keep-alive\r\nHost: google.com\r\n\r\n") + rw.r.WriteString("") + + ch := make(chan struct{}) + go func() { + err := ServeConn(rw, func(ctx *RequestCtx) { + ctx.Hijack(func(c net.Conn) {}) + ctx.SetUserValue("myKey", &closerWithRequestCtx{ + closeFunc: func(_ *RequestCtx) error { + close(ch) + + return nil + }}, + ) + }) + if err != nil { + t.Errorf("unexpected error in ServeConn: %s", err) + } + }() + + select { + case <-ch: + case <-time.After(time.Second): + t.Errorf("Timeout: UserValues should be reset") + } +} + func TestServeConnNonHTTP11KeepAlive(t *testing.T) { t.Parallel() |