summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/staticfiles.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2021-06-16 14:28:34 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2021-06-16 14:28:34 -0600
commite8ae80adca5db7102e646954fcc53827732ceb83 (patch)
tree8c41b80806dee6ffc1a84bfca3d57e576add0d22 /modules/caddyhttp/fileserver/staticfiles.go
parent32c284b54a77b6c4d3b38485ac2b6484c783b825 (diff)
fileserver: Don't persist parsed template (fix #4202)
Templates are parsed at request-time (like they are in the templates middleware) to allow live changes to the template while the server is running. Fixes race condition. Also refactored use of a buffer so a buffer put back in the pool will not continue to be used (written to client) in the meantime. A couple of benchmarks removed due to refactor, which is fine, since we know pooling helps here.
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles.go')
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go9
1 files changed, 0 insertions, 9 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index f2320aa..f151e32 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -15,7 +15,6 @@
package fileserver
import (
- "bytes"
"fmt"
weakrand "math/rand"
"mime"
@@ -24,7 +23,6 @@ import (
"path/filepath"
"strconv"
"strings"
- "sync"
"time"
"github.com/caddyserver/caddy/v2"
@@ -178,7 +176,6 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
} else if os.IsPermission(err) {
return caddyhttp.Error(http.StatusForbidden, err)
}
- // TODO: treat this as resource exhaustion like with os.Open? Or unnecessary here?
return caddyhttp.Error(http.StatusInternalServerError, err)
}
@@ -555,12 +552,6 @@ func (wr statusOverrideResponseWriter) WriteHeader(int) {
var defaultIndexNames = []string{"index.html", "index.txt"}
-var bufPool = sync.Pool{
- New: func() interface{} {
- return new(bytes.Buffer)
- },
-}
-
const (
minBackoff, maxBackoff = 2, 5
separator = string(filepath.Separator)