Repository navigation
v0.6.0
flare v0.6.0 is the five-track HTTP feature pass: HTTP/2, sessions + signed cookies, middleware + CORS + FileServer + brotli, request body parsing (cookies / urlencoded / multipart), and an EPOLLEXCLUSIVE shared-listener multi-worker scheduler with optional cross-worker handoff. Plus a perf pass on the response hot path and a real macOS arm64 FFI lifetime fix.
HTTP/2
- RFC 9113 frame codec (
flare/http2/frame.mojo): DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION; flag + length validation at parse time. - RFC 7541 HPACK encoder + decoder; static + dynamic table; static-table happy path inlined.
- Connection + stream state machines (
flare/http2/state.mojo); h2c upgrade detection on the HTTP/1.1 read path; ALPN dispatch. H2Connectiondriver wired intoHttpServer; new public surface:H2Connection,HpackEncoder, frame codec types underflare.http2.
Request parsing
- Request/response cookie ergonomics + RFC 6265 cookie jars;
Cookiesextractor. application/x-www-form-urlencodedparser +Form[T]extractor (parses, validates, and binds to a struct's fields at extraction time).multipart/form-data(RFC 7578) streaming parser +Multipartextractor; bounded buffer, per-part disposition + content-type.
Sessions + signed cookies
flare.crypto.hmac— HMAC-SHA256 FFI, RFC 4231 vectors. Uses the same OpenSSL we already link for TLS.signed_cookie_encode/signed_cookie_decodelower-level codec with constant-time tag compare.- Typed
Session[T]overCookieSessionStore(stateless; signed cookie carries the payload) andInMemorySessionStore(server-side; signed cookie carries the id).
Middleware + content negotiation
Logger,RequestId,Compress,CatchPanic— each is aHandlerthat wraps anotherHandler, no callback chain. Compiler monomorphises the chain into one direct call sequence per request type.Corsmiddleware: allowlist + preflight;Access-Control-*header writer.FileServerwith HEAD + Range (RFC 9110) support; safe path resolution via_file_exists(now FFI-lifetime-correct on macOS arm64).- gzip + brotli content-encoding (RFC 9110 §12.5.3 q-value parser). Brotli encode/decode through
libbrotlienc/libbrotlidec.
Multi-worker scheduler
HttpServer.serve(handler, num_workers=N)over anEPOLLEXCLUSIVEshared listener on Linux (kernel-balanced accept, no thundering herd).flare.runtime.HandoffQueue— bounded MPSC FIFO of opaque Int tokens guarded bypthread_mutex_t.WorkerHandoffPool+HandoffPolicy.from_env(FLARE_SOAK_WORKERS=on) for application-level work-stealing on skewed-keepalive workloads. Default off; production remains opt-in until v0.7 reactor-side wiring.
Performance
Response.__init__no longer copies the body (wasbody.copy()per request). New_string_to_bytesdoes one bulkresize+memcpyfor the response builders._serialize_responsewrites status +Content-Lengthvia stackitoa(noString(int)heap allocs).- TFB plaintext, EPYC 7R32,
wrk2 -t8 -c256 -d30s, calibrated peak with--latency(CO-corrected):
| Server | Workers | Req/s | p99 ms | p99.99 ms |
|---|---|---|---|---|
| flare_mc (shared listener) | 4 | 170,305 | 2.38 | 3.11 |
| flare (reactor) | 1 | 56,086 | 2.70 | 3.54 |
flare_mc holds the best p99 / p99.9 / p99.99 of the four 4-worker frameworks (vs. hyper / axum / actix_web). flare 1w is 88 % of nginx 1w throughput. Apple M-series 1w: ~157K req/s, ~1.10x Go net/http. Full tables in docs/benchmark.md.
Fixed
- macOS arm64 FFI lifetime bug in
flare/http/{middleware,encoding}.mojo. A function-localOwnedDLHandlewas reclaimed by Mojo's ASAP-destruction rule before the cached function pointer was invoked;dlcloseran first and the pointer dangled, segfaulting the runtime undercompress_brotli/decompress_brotli/_file_exists. Both call sites now route through borrow-the-handle helpers (read lib: OwnedDLHandle), the same idiom the zlib path already uses. - CI macOS leg bumped from
macos-14tomacos-15(Sequoia, arm64); mandatory again, no advisory mode, no retry loop. - 45
mojowarnings across tests / examples / lib audited to zero (deprecatedalias→comptime,from os import *→from std.os import *, implicitInt → UInt8, etc.).
Breaking
Response.__init__now takesvar body / reason / versionand moves them in. Direct callers passingbody=fooneedbody=foo^. Theok/ok_json/bad_request/not_found/internal_errorhelpers are unaffected.
Public API reorganisation
- Top-level
flare/__init__.mojore-exports the common surface sofrom flare import HttpServer, Router, Request, Response, Handler, ok, ok_json, SocketAddr, IpAddr, HttpClient, get, post, num_cpus, default_worker_countresolves without reaching into sub-packages. Sub-package__init__.mojofiles (flare.http,flare.http2,flare.runtime) aligned with the same versionless tone. - All internal version refs (
v0.X.Y, track / phase / step identifiers, design-doc cross-references) stripped from public docstrings;mojo docoutput now describes behaviour, not roadmap.
Compatibility & infra
mojo == 1.0.0b1.dev2026042717pinned acrosspixi.toml+recipe.yaml.- Inlined
jsonsource bumped tov0.1.5(same Mojo pin, verified againstehsanmok/json@v0.1.5/recipe.yaml). mozz(fuzz harness runtime) bumped tov0.1.2.- CI:
ubuntu-22.04+macos-15, both mandatory. - Fuzz: 22 harnesses, 5M+ cumulative runs, zero known crashes (new this release:
fuzz-form,fuzz-multipart,fuzz-session-decode,fuzz-fs-range,fuzz-h2-frame,fuzz-hpack-decoder). - Tests: 961 across 60 files + 36 runnable examples (every example part of
pixi run tests).
Docs
- README rewritten: feature list refreshed for v0.6, Quick start now exposes complexity gradually (Beginner: router + path params; Intermediate: typed extractors + middleware shape; Advanced:
Cancel,ComptimeRouter,App[S]+ middleware composition). docs/cookbook.md: 10 new "I want to..." rows for examples 27–36 (request cookies, urlencoded forms, multipart uploads, signed-cookie sessions, middleware stack, CORS, FileServer, brotli, HTTP/2 driver, work-stealing).docs/architecture.md: layer diagram now listsflare.http2andflare.cryptoas first-class modules; the v0.5 placeholderflare.h2 (planned)line is gone.
Install
[dependencies]
flare = { git = "https://github.com/ehsanmok/flare.git", tag = "v0.6.0" }