You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
│ • Injects validated path into ctx.SetUserValue │
@@ -129,7 +129,7 @@ GET /app.js
129
129
NO → os.Stat → os.ReadFile → cache.Put → serveFromCache
130
130
```
131
131
132
-
When `preload = true`, every eligible file is loaded into cache at startup. The path-safety cache (`sync.Map`) is also pre-warmed, so the very first request for any preloaded file skips both filesystem I/O and `EvalSymlinks`.
132
+
When `preload = true`, every eligible file is loaded into cache at startup. The path-safety cache (bounded LRU) is also pre-warmed, so the very first request for any preloaded file skips both filesystem I/O and `EvalSymlinks`. Symlink targets are validated against the root during the preload walk — symlinks pointing outside root are skipped.
133
133
134
134
---
135
135
@@ -164,7 +164,7 @@ Measured on Apple M2 Pro (`go test -bench=. -benchtime=5s`):
164
164
-**Direct `ctx.SetBody()` fast path**: cache hits bypass range/conditional logic entirely; pre-formatted `Content-Type` and `Content-Length` headers are assigned directly.
165
165
-**Custom Range implementation**: `parseRange()`/`serveRange()` handle byte-range requests without `http.ServeContent`.
166
166
-**Post-processing compression**: compress middleware runs after the handler, compressing the response body in a single pass.
-**GC tuning**: `gc_percent = 400` reduces garbage collection frequency — the hot path avoids all formatting allocations, with only minimal byte-to-string conversions from fasthttp's `[]byte` API.
169
169
-**Cache-before-stat**: `os.Stat` is never called on a cache hit — the hot path is pure memory.
170
170
-**Zero-alloc `AcceptsEncoding`**: walks the `Accept-Encoding` header byte-by-byte without `strings.Split`.
@@ -214,7 +214,8 @@ Only `GET`, `HEAD`, and `OPTIONS` are accepted. All other methods (including `TR
214
214
|`ReadTimeout`| 10 s (covers full read phase including headers — Slowloris protection) |
215
215
|`WriteTimeout`| 10 s |
216
216
|`IdleTimeout`| 75 s (keep-alive) |
217
-
|`MaxRequestBodySize`| 0 (no body accepted — static server) |
217
+
|`MaxRequestBodySize`| 1024 bytes (static file server needs no large request bodies) |
1. At startup, walks every file under `files.root`.
647
-
2. Files smaller than `max_file_size` are read into the LRU cache.
648
-
3. Pre-formatted `Content-Type` and `Content-Length` response headers are computed once per file.
649
-
4. The path-safety cache (`sync.Map`) is pre-warmed — the first request for any preloaded file skips `filepath.EvalSymlinks`.
650
-
5. Preload statistics (file count, total bytes, duration) are logged at startup.
653
+
2. Symlink targets are validated — symlinks pointing outside root are skipped.
654
+
3. Files smaller than `max_file_size` are read into the LRU cache.
655
+
4. Pre-formatted `Content-Type` and `Content-Length` response headers are computed once per file.
656
+
5. The path-safety cache (bounded LRU) is pre-warmed — the first request for any preloaded file skips `filepath.EvalSymlinks`.
657
+
6. Preload statistics (file count, total bytes, duration) are logged at startup.
651
658
652
659
### When to use preload
653
660
@@ -783,6 +790,17 @@ The most common causes:
783
790
784
791
The server only accepts `GET`, `HEAD`, and `OPTIONS`. Any other method (POST, PUT, DELETE, PATCH, TRACE, etc.) is rejected with `405`. This is intentional — it's a static file server, not an API. If your browser is sending a `POST` request, check your HTML form actions and JavaScript fetch calls.
785
792
793
+
### `413 Payload Too Large`
794
+
795
+
A file exceeds the `max_serve_file_size` limit (default 1 GB). Increase the limit in config:
796
+
797
+
```toml
798
+
[files]
799
+
max_serve_file_size = 2147483648 # 2 GB
800
+
```
801
+
802
+
Or set to 0 to disable the limit entirely. This also applies via the `STATIC_FILES_MAX_SERVE_FILE_SIZE` environment variable.
803
+
786
804
### Files are stale after a deploy
787
805
788
806
The in-memory cache serves files from memory after the first request (or immediately if `preload = true`). After deploying new files to disk, flush both the file cache and the path-safety cache:
0 commit comments