valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.73k stars 1.75k forks source link

Fix Different request paths share the same `fs` cache is some cases. #1843

Closed newacorn closed 1 month ago

newacorn commented 1 month ago

For requests with paths that do not have a trailing slash, we always redirect to the corresponding path with a trailing slash. This approach avoids assuming that users will definitely be redirected to the trailing-slash path and instead ensures that we return a proper redirection, checking for an index file or generating a directory listing. We do this because we should not make assumptions about user behavior. Similarly, the cache for dir/ requests should not be used for dir requests. This issue is also reflected in this issue: https://github.com/valyala/fasthttp/issues/1839

~/GolandProjects/cbrotli_bug/fasthttp fasthttp_test_issue2 56s
❯ go test -race --count=2 .
--- FAIL: TestZstdBytesConcurrent (1.03s)
    zstd_test.go:22: timeout
--- FAIL: TestZstdCompressConcurrent (1.02s)
    zstd_test.go:68: timeout
--- FAIL: TestServeFileDirectoryRedirect (0.00s)
    fs_test.go:926: Unexpected status code 200 for directory '/fasthttputil' without trailing slash. Expecting 302.
--- FAIL: TestZstdBytesConcurrent (1.00s)
    zstd_test.go:22: timeout
FAIL
FAIL    github.com/valyala/fasthttp 16.511s
FAIL
erikdubbelboer commented 1 month ago

Nice find, thanks!