Serve Extras
Each costs nothing for routes that do not use it.
| Feature | What it does |
|---|---|
| gzip | Embedded text files (wisp.js, app css, client modules, static/ in a release build) are compressed once, on a thread the first request with accept-encoding: gzip starts (that request gets the file as is). Output is within 2% of gzip -9 and reused (vary: accept-encoding). Pages and API answers are not compressed unless the route sets const COMPRESS: bool = true; (below). |
| brotli | A release build also compresses the embedded text files (wisp.js, live.js, app css, static/, the PWA worker and manifest) and the pages wisp build prerendered with brotli at quality 11, and embeds the .br next to the file. A request whose accept-encoding lists br (not as q=0; a bare * does not count) gets it as is, with content-encoding: br, vary: accept-encoding and the file's etag made weak; otherwise gzip or the file, as before. It is left out when not smaller than the gzip, under 256 bytes, in the edge wasm, and for an app with an html hook. Brotli is never made while the server runs. Ranges read the file as is. Client modules (/_app/c/) and NPM files are not built as brotli yet, and COMPRESS answers are gzip only. |
| Range | Files answer range: bytes=a-b, a- and -n with 206 and content-range. A range past the end gets 416. Only one range is supported: several, or a malformed one, get the whole file. if-range is honored with the file's etag. Only GET reads a range (RFC 9110): a HEAD gets the whole file's 200 head. |
| Security headers | HTML and error pages carry x-content-type-options: nosniff and a referrer-policy (strict-origin-when-cross-origin; on an onion site no-referrer; WISP_REFERRER names another). They are not added when the app sets its own. |
| Compressed answers | A page or +server.rs with const COMPRESS: bool = true; sends gzip when the request's accept-encoding accepts it and the answer is text (text/*, JSON, JavaScript, XML, SVG) of 1 KB or more that got smaller. It adds vary: accept-encoding and makes an etag weak (W/"…"). A HEAD is compressed as its GET is, so its content-length, content-encoding and etag match the GET's. It skips range requests, 204, 206, redirects, errors, streams, text/event-stream, WebSockets, and answers with their own content-encoding, content-length or cache-control: no-transform. It conflicts with CACHE (a build error). Gzip only; brotli would need a dependency. |
| Early hints | A page that waits for data (a load, an async call) first sends 103 Early Hints with link preloads for the app css, fonts and browser modules, then its 200. The build bakes the links from the page head's URLs, so nothing is formatted per request. On by default over HTTP/2; off over HTTP/1.1, where old clients and proxies break on a 1xx (const EARLY_HINTS_H1: bool = true; turns it on). The 200 carries the same link header, which Cloudflare and other CDNs turn into their own 103; edge targets send only that header. const EARLY_HINTS: bool = false; turns it off for a page or layout. The link value stops at 4 KB (css and fonts first; the build warns and names the route). Not in dev. |
| Health | GET /_wisp/health answers 200 ok, and 503 stopping once the server drains. |
| Handler timeout | A handler still waiting after the limit is dropped and the server answers 503. It is checked at awaits, so a handler that blocks its thread is not stopped. |
| Env var | What it does |
|---|---|
WISP_HSTS=on | adds strict-transport-security (one year, subdomains) to every answer. Not sent to a plain-http request (x-forwarded-proto: http, or a .onion host) |
WISP_ONION=on | serves as a Tor onion service (automatic for a .onion ORIGIN or SITE_URL); see Tor onion services |
WISP_ONION_LOCATION=xyz.onion | adds onion-location to the clearnet site's pages |
WISP_SECURE_HEADERS=off | leaves out the first two security headers |
WISP_HANDLER_TIMEOUT=30 | handler timeout in seconds (not for a WebSocket handler: WISP_WS_IDLE closes a quiet client while the handler waits in recv, and a handler that does not read must stop on Gone) |
Is This Page Useful?