aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/fileserver/browsetplcontext.go
diff options
context:
space:
mode:
authorAbdussamet Koçak <[email protected]>2022-10-08 21:56:35 +0300
committerGitHub <[email protected]>2022-10-08 12:56:35 -0600
commit33f60da9f2d6edc5de550275f043c4262d23f6ca (patch)
treef4ae6156456d934f0857feb998746d0c40120223 /modules/caddyhttp/fileserver/browsetplcontext.go
parentb4e28af953aa02fb44f88c155956488b1f473348 (diff)
downloadcaddy-33f60da9f2d6edc5de550275f043c4262d23f6ca.tar.gz
caddy-33f60da9f2d6edc5de550275f043c4262d23f6ca.zip
fileserver: stop listing dir when request context is cancelled (#5131)
Prevents caddy from performing disk IO needlessly when the request is cancelled before the listing is finished. Closes #5129
Diffstat (limited to 'modules/caddyhttp/fileserver/browsetplcontext.go')
-rw-r--r--modules/caddyhttp/fileserver/browsetplcontext.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/caddyhttp/fileserver/browsetplcontext.go b/modules/caddyhttp/fileserver/browsetplcontext.go
index cd24fc232..172fa505a 100644
--- a/modules/caddyhttp/fileserver/browsetplcontext.go
+++ b/modules/caddyhttp/fileserver/browsetplcontext.go
@@ -15,6 +15,7 @@
package fileserver
import (
+ "context"
"io/fs"
"net/url"
"os"
@@ -30,13 +31,17 @@ import (
"go.uber.org/zap"
)
-func (fsrv *FileServer) directoryListing(entries []fs.DirEntry, canGoUp bool, root, urlPath string, repl *caddy.Replacer) browseTemplateContext {
+func (fsrv *FileServer) directoryListing(ctx context.Context, entries []fs.DirEntry, canGoUp bool, root, urlPath string, repl *caddy.Replacer) browseTemplateContext {
filesToHide := fsrv.transformHidePaths(repl)
var dirCount, fileCount int
fileInfos := []fileInfo{}
for _, entry := range entries {
+ if err := ctx.Err(); err != nil {
+ break
+ }
+
name := entry.Name()
if fileHidden(name, filesToHide) {