Skip to content

Commit

Permalink
Fix Different request paths share the same fs cache is some cases. (#…
Browse files Browse the repository at this point in the history
…1843)

Currently, the implementation may result in shared fs cache between requests for dir and dir/.
  • Loading branch information
newacorn authored Aug 31, 2024
1 parent 19c50cd commit b0ea03f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {
path = ctx.Path()
}
hasTrailingSlash := len(path) > 0 && path[len(path)-1] == '/'
path = stripTrailingSlashes(path)

if n := bytes.IndexByte(path, 0); n >= 0 {
ctx.Logger().Printf("cannot serve path with nil byte at position %d: %q", n, path)
Expand Down Expand Up @@ -1061,9 +1060,13 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {
}
}

pathStr := string(path)
originalPathStr := string(path)
pathStr := originalPathStr
if hasTrailingSlash {
pathStr = originalPathStr[:len(originalPathStr)-1]
}

ff, ok := h.cacheManager.GetFileFromCache(fileCacheKind, pathStr)
ff, ok := h.cacheManager.GetFileFromCache(fileCacheKind, originalPathStr)
if !ok {
filePath := h.pathToFilePath(pathStr)

Expand Down Expand Up @@ -1098,7 +1101,7 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {
return
}

ff = h.cacheManager.SetFileToCache(fileCacheKind, pathStr, ff)
ff = h.cacheManager.SetFileToCache(fileCacheKind, originalPathStr, ff)
}

if !ctx.IfModifiedSince(ff.lastModified) {
Expand Down

0 comments on commit b0ea03f

Please sign in to comment.