Skip to content

v0.6.0

Choose a tag to compare

@ehsanmok ehsanmok released this 30 Apr 20:06
· 1127 commits to main since this release

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.
  • H2Connection driver wired into HttpServer; new public surface: H2Connection, HpackEncoder, frame codec types under flare.http2.

Request parsing

  • Request/response cookie ergonomics + RFC 6265 cookie jars; Cookies extractor.
  • application/x-www-form-urlencoded parser + Form[T] extractor (parses, validates, and binds to a struct's fields at extraction time).
  • multipart/form-data (RFC 7578) streaming parser + Multipart extractor; 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_decode lower-level codec with constant-time tag compare.
  • Typed Session[T] over CookieSessionStore (stateless; signed cookie carries the payload) and InMemorySessionStore (server-side; signed cookie carries the id).

Middleware + content negotiation

  • Logger, RequestId, Compress, CatchPanic — each is a Handler that wraps another Handler, no callback chain. Compiler monomorphises the chain into one direct call sequence per request type.
  • Cors middleware: allowlist + preflight; Access-Control-* header writer.
  • FileServer with 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 an EPOLLEXCLUSIVE shared listener on Linux (kernel-balanced accept, no thundering herd).
  • flare.runtime.HandoffQueue — bounded MPSC FIFO of opaque Int tokens guarded by pthread_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 (was body.copy() per request). New _string_to_bytes does one bulk resize + memcpy for the response builders. _serialize_response writes status + Content-Length via stack itoa (no String(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-local OwnedDLHandle was reclaimed by Mojo's ASAP-destruction rule before the cached function pointer was invoked; dlclose ran first and the pointer dangled, segfaulting the runtime under compress_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-14 to macos-15 (Sequoia, arm64); mandatory again, no advisory mode, no retry loop.
  • 45 mojo warnings across tests / examples / lib audited to zero (deprecated alias → comptime, from os import * → from std.os import *, implicit Int → UInt8, etc.).

Breaking

  • Response.__init__ now takes var body / reason / version and moves them in. Direct callers passing body=foo need body=foo^. The ok / ok_json / bad_request / not_found / internal_error helpers are unaffected.

Public API reorganisation

  • Top-level flare/__init__.mojo re-exports the common surface so from flare import HttpServer, Router, Request, Response, Handler, ok, ok_json, SocketAddr, IpAddr, HttpClient, get, post, num_cpus, default_worker_count resolves without reaching into sub-packages. Sub-package __init__.mojo files (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 doc output now describes behaviour, not roadmap.

Compatibility & infra

  • mojo == 1.0.0b1.dev2026042717 pinned across pixi.toml + recipe.yaml.
  • Inlined json source bumped to v0.1.5 (same Mojo pin, verified against ehsanmok/json@v0.1.5/recipe.yaml).
  • mozz (fuzz harness runtime) bumped to v0.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 lists flare.http2 and flare.crypto as first-class modules; the v0.5 placeholder flare.h2 (planned) line is gone.

Install

[dependencies]
flare = { git = "https://github.com/ehsanmok/flare.git", tag = "v0.6.0" }