Product knowledge · Advanced · Filesystem boundary

A URL path is not filesystem authority.

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

Choose by authority, not extension

SurfaceWho selects the fileUse for
Static mountDeployment/app declaration grants a public root.JS, CSS, images, fonts and public built assets.
SPA fallbackRoute policy returns index for unmatched navigation paths.Client-side routes; never replace an API 404.
File responseApplication 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

Explicit application routes beat static fallback

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 HTML

Keep 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

Mount only what is truly public

04 · SPA fallback

Navigation fallback is not a business router

Accept

A navigation path belongs to frontend scope and needs index for the client router.

Reject

API paths, file requests, unsuitable methods or requests that do not accept HTML.

Cache

Index and hashed assets have different lifecycle/cache policies; deployment owns versioning.

Security

Fallback never bypasses handler authorization or turns a private file into a public asset.

05 · Authorized file response

Authorize the business object, then select the file

1

Parse business identity

For example an invoice ID; never treat the request path as an OS path.

2

Authenticate + authorize

Application decides whether the principal may read the object.

3

Resolve inside authority

Map the object to a relative path or application file reference already confined.

4

Return file intent

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

Client cache and partial reads have distinct terminals

200
Full representation with validator and length facts under contract.
206
Satisfiable byte range with matching Content-Range.
304
Validator matches; no new representation body.
416
Unsatisfiable range; never silently return the full file.

Use 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

File response is the contract; sendfile is one eligible path

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.

No zero-copy promise

Cache, storage, protocol, kernel and client speed still affect copies and CPU.

Never disable TLS

The security boundary outweighs a fast path; mechanism is not an application knob.

No inferred performance

A successful download proves no syscall/backend; matching-host evidence is required.

Not upload

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

Refuse at the boundary without leaking filesystem detail

FailureOwner action
Outside authority / invalid pathFail closed; never normalize into another file.
Not authorizedApplication returns a public-safe refusal without revealing existence or path.
Missing/changed fileMap under application/API contract; keep operator details separate.
Pressure/timeout/disconnectRelease transfer state; never create connector retries without bounds.
Close refusalRetain owner and filesystem dependencies until work converges safely.

09 · Integration checklist

Before choosing a language API