diff options
author | Sergio VS <savsgio.engineer@gmail.com> | 2021-12-16 05:27:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 05:27:02 +0100 |
commit | 258a4c17b4f451f9a1f9bae3f34d3f5d6e9e0bfd (patch) | |
tree | a3f997786dd12d755c28d7771567b7fe4607be58 /server_test.go | |
parent | Use %w to wrap errors (#1175) (diff) | |
download | fasthttp-258a4c17b4f451f9a1f9bae3f34d3f5d6e9e0bfd.tar.gz fasthttp-258a4c17b4f451f9a1f9bae3f34d3f5d6e9e0bfd.tar.bz2 fasthttp-258a4c17b4f451f9a1f9bae3f34d3f5d6e9e0bfd.zip |
fix: reset response after reset user values on keep-alive connections (#1176)
Diffstat (limited to 'server_test.go')
-rw-r--r-- | server_test.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server_test.go b/server_test.go index 2f7e6ae..0a199b8 100644 --- a/server_test.go +++ b/server_test.go @@ -14,6 +14,7 @@ import ( "net" "os" "reflect" + "regexp" "strings" "sync" "testing" @@ -2041,23 +2042,28 @@ func TestRequestCtxWriteString(t *testing.T) { } } -func TestServeConnKeepRequestValuesUntilResetUserValues(t *testing.T) { +func TestServeConnKeepRequestAndResponseUntilResetUserValues(t *testing.T) { t.Parallel() reqStr := "POST /foo HTTP/1.0\r\nHost: google.com\r\nContent-Type: application/octet-stream\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n" + respRegex := regexp.MustCompile("HTTP/1.1 308 Permanent Redirect\r\nServer: fasthttp\r\nDate: (.*)\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n") rw := &readWriter{} rw.r.WriteString(reqStr) - var resultReqStr string + var resultReqStr, resultRespStr string ch := make(chan struct{}) go func() { err := ServeConn(rw, func(ctx *RequestCtx) { + ctx.Response.SetStatusCode(StatusPermanentRedirect) + ctx.SetUserValue("myKey", &closerWithRequestCtx{ ctx: ctx, closeFunc: func(closerCtx *RequestCtx) error { resultReqStr = closerCtx.Request.String() + resultRespStr = closerCtx.Response.String() + return nil }}) }) @@ -2076,6 +2082,10 @@ func TestServeConnKeepRequestValuesUntilResetUserValues(t *testing.T) { if resultReqStr != reqStr { t.Errorf("Request == %s, want %s", resultReqStr, reqStr) } + + if !respRegex.MatchString(resultRespStr) { + t.Errorf("Response == %s, want regex %s", resultRespStr, respRegex) + } } func TestServeConnNonHTTP11KeepAlive(t *testing.T) { |