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
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 fordir
requests. This issue is also reflected in this issue: https://github.com/valyala/fasthttp/issues/1839