@ultimat3/http 🌐
A thin, owned layer over Bun.serve. Not a framework-agnostic HTTP kit — the
lifecycle belongs to us so ALS context, tracing, locale/tz and authz are impossible
to skip.
bun add @ultimat3/http · guide: Routes And Render Modes
import { configureHttp } from '@ultimat3/http';
configureHttp({ bodyLimitBytes: 8 * 1024 * 1024, requestTimeoutMs: 300_000 });
What it owns
| Concern |
Module |
server lifecycle, drain, /healthz + /readyz |
server.ts; health-disclosure.ts owns the healthDetailPeers key, its screen and the proxy half — the body rule is @ultimat3/core's |
route table, matcher, describeRoutes() |
router.ts |
a pathname's segments, their decoding, and its ONE spelling (canonicalPath) — shared by the matcher and by every store keyed on an address; ctx.routePath and requestAddress(ctx) say where a request was matched |
route-path.ts, locale-prefix.ts |
| the ordered request lifecycle |
pipeline.ts |
| typed request (params, query, body) |
request.ts |
response constructors + problem() |
response.ts |
| code → status, closed table |
error-map.ts, composing error-map-http.ts + error-map-tier-<n>.ts |
factsOf(), the problem document, the terminal lines |
error-facts.ts |
token-bucket limiting, toBucket |
rate-limit.ts |
| the app's own HTTP declaration, and the boot's facts over it |
app-config.ts |
| CORS, CSP/HSTS |
cors.ts, security-headers.ts |
| CSRF (origin proof for an unsafe request a browser sent) |
csrf.ts |
the request deadline and ctx.signal |
deadline.ts |
| the caller's real address behind a proxy |
forwarded.ts |
| the inbound request id and trace, read before the span |
correlation.ts |
the server span (OpenTelemetry's stable http.*/url.*/server.* names, ultimate.request_id) and http.request on core's instrumentation bus, once per request |
pipeline.ts |
| dev error overlay |
overlay.ts |
whether the caller is THIS machine — callerLocality({ ip, headers }) → 'local' \| 'relayed' \| 'remote' (CallerLocality), RELAY_HEADERS |
local-caller.ts |
the listener's own TLS (tls: { cert, key }, both PEMs or neither) |
config-tls.ts |
What an app declares: configureHttp()
// apps/web/app/http.ts — module scope, imported by the app like any other module
import { configureHttp } from '@ultimat3/http';
configureHttp({
cors: { origins: ['https://app.example.com'], credentials: true },
bodyLimitBytes: 8 * 1024 * 1024, // this API takes a 4 MB CSV
requestTimeoutMs: 300_000, // and an export that really does take five minutes
rateLimit: {
tenantBucket: 'tenant',
buckets: { tenant: { capacity: 5_000, refillPerSecond: 100 } },
},
});
One registration, read once by whatever process starts the web role — the same seam
configureAuthenticator(authenticate, { credentialTtlMs? }) is. credentialTtlMs is what a
resolved identity is worth on a connection that carries no further request (the sync node's
websocket re-asks after it; omitted, five minutes) — the credential's lifetime is the
authenticator's fact, so it is declared beside the function, never as a second authenticator. The
authenticator answers "nobody" with null — or with a session refusal it throws (X_UNAUTHENTICATED,
X_SESSION_EXPIRED: core's isSessionRefusal), which the auth stage reads as the same anonymous
actor, so a stale cookie still reaches sign-in and a required route answers it the no-cookie 401. Any
other throw propagates. Breaking, As of 2026-08-24: before it, the only HttpConfig
any shipped process built was a fixed literal inside @ultimat3/cli, so none of the four values
above could be set from an app at all — cors.origins was [] in every deployment, which refuses
every cross-origin browser call, permanently. AppConfig has never carried an http key and does
not gain one: @ultimat3/core is tier 0 and cannot hold this package's types.
cors.allowHeaders and cors.exposeHeaders default to what the typed clients send and read, off
core's constants (idempotency-key, x-request-timeout-ms, traceparent; x-ultimate-records,
x-ultimate-dates, x-ultimate-replayed, ratelimit-*, deprecation, sunset, link), so
listing an origin is the whole declaration. A list of the app's own replaces the default whole.
x-ultimate-dates is capped at WIRE_DATES_MAX_BYTES (1,536 bytes), As of 2026-11-19: a 4 KB proxy buffer holds the status line and every header, and the framework's own
block (security headers, CSP, CORS, rate-limit, trace ids, one sealed cookie) measures ~2 KB.
cappedWireDates(data, ctx?) is the one writer — an action's and a query's 200, and a streamed
frame's dates: line. An answer whose instants need one path each (a string | Date column, a
[label, instant] tuple) past the cap is sent with no header: a proxy refuses a response whose
headers outgrow its buffer (nginx's default proxy_buffer_size is one page). The client then reads
those instants as the ISO strings the body holds, and the route's name is logged once per process
at warn (http.wire_dates_dropped, with paths, bytes, maxBytes).
AppHttpConfig is Omit<HttpConfigInput, BootOwnedHttpKey> — port, hostname, dev,
buildId, signInPath, trustProxy, trustedProxyHops and rateLimit.scope are the boot's, and
writing one here is a type error rather than a value silently overwritten at the next boot.
mergeHttpConfig(configuredHttp(), boot) is the layering, and it merges security.csp.extend per
directive: the app's CDN source and the boot's inline-script hash are each the whole answer for
something.
The pipeline is the guarantee
request-id → admit → trace → context → locale → auth → rate-limit → csrf → body → authz
→ handler → cache-headers → (error-map) → response → compress
Exported as PIPELINE_STAGES, each entry carrying a why. pipeline.test.ts
asserts the order. Ordering rules worth restating: