Wisp is in pre-release, self-hosted since GitHub suspended us. Install it, or see the changelog.

Wisp

Serve Extras

Each costs nothing for routes that do not use it.

FeatureWhat it does
gzipEmbedded 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, also on a 304 for wisp.js and live.js). Pages and API answers are not compressed unless the route sets const COMPRESS: bool = true; (below).
brotliA 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. Embedded files have no zstd copy: brotli made at build time at quality 11 beats an encoder run per request. COMPRESS answers are in the row below.
RangeFiles 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. An if-range that is not UTF-8 gets the whole file, and so does a range that is not UTF-8. Only GET reads a range (RFC 9110): a HEAD gets the whole file's 200 head. cx.file_in answers range the same way. Its if-range can name the file's etag. An if-range with a date always gets the whole file (RFC 9110 13.1.5).
ETagcx.file_in sends an etag (the modification time and size of the file), last-modified and cache-control: no-cache. A GET or HEAD whose if-none-match names the tag gets a 304. With no if-none-match, an if-modified-since that is not older than the file gets a 304. A file with no known time, or a time before 1970, has no tags. Only if-none-match: * gets its 304. More than 1 MiB of the file (the whole file or one range) goes out in pieces of 64 KiB with the content-length of those bytes. If such a file gets shorter during the send, the connection ends, so the client sees that the answer is not complete.
Security headersHTML 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 answersA page or +server.rs with const COMPRESS: bool = true; sends gzip when the request's accept-encoding accepts it. The cargo features compress-br and compress-zstd of wisp add brotli (quality 4) and zstd (about level 1). They are off by default and not in the edge build. The answer must be text of 1 KB or more that got smaller. Wisp reads the media type alone (before any ;), in any case. Text is text/*, a type that names json, javascript or wasm, or XML as the subtype xml or a +xml suffix (image/svg+xml). A .docx type (application/vnd.openxmlformats-..) does not count: the file is a zip. A media type over 255 bytes (RFC 6838 4.2) does not count. Embedded files use the same rule. The route 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. The route skips range requests (also a range that is not UTF-8), 204, 206, redirects, errors, streams, text/event-stream and WebSockets. It also skips answers with their own content-encoding, content-length or a cache-control with the no-transform directive (in any case). It reads these headers on the Response and those that cx.set_header set. It decides before after in src/hooks.rs runs. It conflicts with CACHE (a build error). The coding is the one with the highest q in the request. On a tie, zstd wins over brotli and brotli over gzip, the order of tower-http's Encoding. A client must name br or zstd. * gets gzip. A coding with q=0 is not used. A q that is not digits with at most one . counts as 0. A coding that is not built is never sent. If the brotli or zstd encoder fails, the answer goes as gzip when the request takes gzip, else as it is. An app built with panic = "abort" stops when an encoder panics. An answer can hold a secret and also text from the request. When Wisp compresses such an answer, its size can show the secret to an attacker (BREACH). Wisp does not pad or mask the answer. Set COMPRESS only on routes whose answers never hold both. A streamed page ({#await}) follows the same rule: gzip only with COMPRESS, and never with cache-control: no-transform. A PPR page is never gzip. Wisp does not prevent BREACH: keep a secret and text from the request out of one compressed answer, or leave COMPRESS off for that route. A streamed page is never brotli or zstd.
Early hintsA 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.
HealthGET /_wisp/health answers 200 ok, and 503 stopping once the server drains.
Handler timeoutA 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 varWhat it does
WISP_HSTS=onadds strict-transport-security (one year, subdomains) to every answer. Not sent to a plain-http request. A named proxy says x-forwarded-proto: http, or the Host is a .onion with no TLS and no x-forwarded-proto. An onion site (WISP_ONION=on) never sends it
WISP_ONION=onserves as a Tor onion service (automatic for a .onion ORIGIN or SITE_URL); see Tor onion services
WISP_ONION_LOCATION=xyz.onionadds onion-location to the clearnet site's pages
WISP_SECURE_HEADERS=offleaves out the first two security headers
WISP_HANDLER_TIMEOUT=30handler 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?

View This Page's Source

Type to search every docs page and heading.