Skip to content

Commit 5de4c35

Browse files
committed
fix: stabilize static FS serving and session pool reuse
- Static middleware: use empty Root instead of "." for io/fs.FS so fasthttp's pathToFilePath returns "" instead of ".", avoiding the openIndexFile bug that builds invalid "./index.html" paths on all platforms without requiring a vendor patch. - SendFile: remove redundant Root = "." override for io/fs.FS since Root is already "" with AllowEmptyRoot enabled. - Session: call Reset() in acquireData() after pool Get to prevent dirty data objects from leaking keys across parallel tests.
1 parent 06ad7b6 commit 5de4c35

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

middleware/session/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var dataPool = sync.Pool{
3333
func acquireData() *data {
3434
obj := dataPool.Get()
3535
if d, ok := obj.(*data); ok {
36+
d.Reset()
3637
return d
3738
}
3839
// Handle unexpected type in the pool

middleware/static/static.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ func New(root string, cfg ...Config) fiber.Handler {
163163
prefixLen--
164164
}
165165

166-
// For io/fs.FS, Root must be a directory path (not a filename).
167-
// Use "." as Root and let PathRewrite handle file-root cases.
166+
// For io/fs.FS, Root must be empty so fasthttp's pathToFilePath
167+
// returns clean relative paths without prefixing the root.
168+
// PathRewrite already handles file-root and subdirectory cases.
168169
fsRoot := root
169170
if config.FS != nil {
170-
fsRoot = "."
171+
fsRoot = ""
171172
}
172173

173174
fileServer := &fasthttp.FS{

res.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,6 @@ func (r *DefaultRes) SendFile(file string, config ...SendFile) error {
835835
},
836836
}
837837

838-
if cfg.FS != nil {
839-
fasthttpFS.Root = "."
840-
}
841-
842838
sf := &sendFileStore{
843839
config: cfg,
844840
handler: fasthttpFS.NewRequestHandler(),

0 commit comments

Comments
 (0)