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
{{ message }}
Repository navigation
Commit 71e2519
Browse filesBrowse the repository at this point in the historyBrowse files
These options can be altered when calling `reply.sendFile('filename.html', options)` or `reply.sendFile('filename.html', 'otherfilename.html', options)` on each response.
220
221
222
+
`onFile(path, stat)` receives the selected file's absolute path and file system statistics. It may return a promise, which is awaited before response processing and streaming begin. A thrown error or rejected promise aborts the operation and is handled by Fastify's error pipeline. When `allowedPath` is configured, final-path authorization runs first; denied files do not invoke `onFile`.
223
+
221
224
#### `redirect`
222
225
223
226
Default: `false`
@@ -254,10 +257,10 @@ when using the `wildcard: false` option.
254
257
255
258
Default: `(pathName, root, request) =>true`
256
259
257
-
This function filters served files. Accepted `pathName`values are normalized before the callback runs; non-canonical forms such as `//file`, `/./file`, and `/path//file` are rejected. A root-relative filesystem alias that resolves a candidate with different letter casing is rejected before that candidate is authorized or served. Using the request object, complex path authentication is possible.
This function filters served files. It runs for the normalized requested `pathName`and may run again when index or extension resolution selects a different final logical path. Final paths use the same leading-slash or relative style as the requested path and are relative to the `root` that selected the file. When `sendFile` is called with an absolute path and no root, `root` is `undefined` and requested and final paths remain absolute. Non-canonical forms such as `//file`, `/./file`, and `/path//file` are rejected. A root-relative filesystem alias that resolves a candidate with different letter casing is rejected before that candidate is authorized or served. Using the request object, complex path authentication is possible.
261
+
Returning `true`from every invocation serves the file; returning `false`for either the requested or final path calls Fastify's 404 handler.
259
262
260
-
When using `preCompressed: true`, `allowedPath` receives the requested path rather than the selected `.br` or `.gz` variant; see the `preCompressed` note below before using extension-based access rules.
263
+
When using `preCompressed: true`, `.br`, `.gz`, and `.deflate` representations are authorized as their logical uncompressed path. For example, a selected compressed index is authorized as `/dir/index.html`, not `/dir/index.html.br`; see the `preCompressed` note below before using extension-based access rules.
261
264
262
265
#### `index`
263
266
@@ -478,7 +481,7 @@ First, try to send the brotli encoded asset (if supported by `Accept-Encoding` h
478
481
479
482
When `preCompressed` is enabled the response includes `Vary: Accept-Encoding`, because the served variant is selected from the request `Accept-Encoding` header. This applies even when the uncompressed file is sent as a fallback, so that shared caches do not return the wrong variant to clients with a different `Accept-Encoding`.
480
483
481
-
> ⚠ Warning: `allowedPath` is evaluated against the requested path rather than the selected pre-compressed variant. A request for `/file.txt` can serve `/file.txt.gz`or `/file.txt.br` when the client accepts that encoding, even if direct requests to `.gz` or `.br` files are denied by `allowedPath`. Treat pre-compressed files as public alternate encodings of the same asset: keep restricted compressed files outside the served root, disable `preCompressed`, or deny the base path too.
484
+
> ⚠ Warning: `allowedPath` evaluates pre-compressed variants as their logical uncompressed paths. A request for `/file.txt` can serve `/file.txt.gz`, `/file.txt.br`, or `/file.txt.deflate` when the client accepts that encoding, without separately authorizing the compression suffix. Treat pre-compressed files as alternate encodings of the same asset and apply access rules to the logical path.
482
485
483
486
Assume this structure with the compressed asset as a sibling of the uncompressed counterpart:
0 commit comments