Parse business identity
For example an invoice ID; never treat the request path as an OS path.
Product knowledge · Advanced · Filesystem boundary
Use a static mount for public assets, SPA fallback for navigation and a confined file response for application-authorized downloads. They share delivery mechanics, not trust policy.
This page covers downloads: server → client. sendfile can send an existing file in a response. To receive a file client → server, use the upload exercises. See how to resume a large upload.
01 · Three file surfaces
| Surface | Who selects the file | Use for |
|---|---|---|
| Static mount | Deployment/app declaration grants a public root. | JS, CSS, images, fonts and public built assets. |
| SPA fallback | Route policy returns index for unmatched navigation paths. | Client-side routes; never replace an API 404. |
| File response | Application authorizes, then selects a relative file within authority. | Private reports, invoices or user-owned downloads. |
Core owns resolution, validators, ranges, pressure and delivery. Application owns authorization and business mapping. Deployment owns asset bytes, publication and replacement.
02 · Route precedence
GET /api/orders/7 → explicit API route
GET /assets/app.js → static mount
GET /app/customer/7 → SPA index fallback
GET /api/missing → API 404/refusal, not SPA HTMLKeep an explicit API namespace. Fallback serves selected navigation only; never swallow typos, authorization failures or missing APIs and return HTML 200.
03 · Public static root
04 · SPA fallback
A navigation path belongs to frontend scope and needs index for the client router.
API paths, file requests, unsuitable methods or requests that do not accept HTML.
Index and hashed assets have different lifecycle/cache policies; deployment owns versioning.
Fallback never bypasses handler authorization or turns a private file into a public asset.
05 · Authorized file response
For example an invoice ID; never treat the request path as an OS path.
Application decides whether the principal may read the object.
Map the object to a relative path or application file reference already confined.
Core validates, accounts and delivers; handler need not read the whole file into bytes.
Never: concatenate ?path=/etc/passwd, a filename or decoded capture directly under a filesystem root.
06 · Validators and ranges
200206304416Use the runtime validator/range contract; do not reimplement header parsing in handlers. Test full, partial, cached, missing, invalid-path and interrupted downloads.
07 · Delivery mechanism
Eligible plaintext HTTP/1.1 delivery may use a native sendfile path. TLS, HTTP/2, HTTP/3 and other platforms use their appropriate bounded path. Core selects mechanism and fallback; connectors do not build a second socket/file loop.
Cache, storage, protocol, kernel and client speed still affect copies and CPU.
The security boundary outweighs a fast path; mechanism is not an application knob.
A successful download proves no syscall/backend; matching-host evidence is required.
Sendfile does not parse multipart, choose a destination or persist incoming bytes.
Range resumes a download from a response; next_offset resumes an upload to the server. See the resumable upload example.
08 · Failure law
| Failure | Owner action |
|---|---|
| Outside authority / invalid path | Fail closed; never normalize into another file. |
| Not authorized | Application returns a public-safe refusal without revealing existence or path. |
| Missing/changed file | Map under application/API contract; keep operator details separate. |
| Pressure/timeout/disconnect | Release transfer state; never create connector retries without bounds. |
| Close refusal | Retain owner and filesystem dependencies until work converges safely. |
09 · Integration checklist