← Back to Pull requests

Parse MIME types in Rust, for C++ and TypeScript callers alike #8868

Closed
unknown closed this pull request without merging on Nov 26, 2026 11:41 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 09:30 UTC
Author

The motivation for this change is to give workerd one WHATWG MIME type
parser, in Rust, for both its C++ and its TypeScript code. It parses
untrusted Content-Type values for Blob, Body, Response, FormData and
fetch, whose callers stay in C++ for now. The new mimetype-rs crate
parses, extracts, validates and serializes MIME types behind
mimetype.h, so no C++ caller changes. The new RUST_MIMETYPE autogate,
checked on every call, chooses between it and the C++ code, which
moves unchanged to mimetype-legacy.c++ and stays as the gate-off path
and the reference for a differential test until a later change deletes
it. TypeScript reaches the same parser through native functions that,
under the gate, hand JS strings to Rust as UTF-8 slices of one buffer.
The bootstrap gets a MimeType class over utils.mimeTypeParse() and
mimeTypeSerialize(), which EventSource uses, and node:util MIMEType
drops its own TypeScript copy of the parser for node-internal:util, so
it parses as Blob and fetch do.

The Rust code matches the C++ byte for byte, quirks included ('\' is a
token character, a "boundary" parameter is serialized after a space, a
repeated parameter keeps its first value), so Workers see the same
MIME types and Content-Type values whichever implementation runs.
mimetype-legacy-test compares the two over about 320,000 generated and
random inputs, and the TypeScript parser node:util drops reproduced
the C++ one, so mimetype-test, including its patched-built-ins case,
passes unchanged; the Blob, Body, FormData, fetch, EventSource,
node:util and WPT MIME suites pass in all variants. The new
mimetype-bench compares node:util MIMEType before and after (medians
of three release runs on one CPU model, Rust path): parsing takes
0.57x of the old TypeScript time for text/plain (543 ns against 950
ns) and 0.64x with 20 parameters (6.7 us against 10.5 us), and
essence, params.get() and iteration take 0.76x to 0.81x, while
toString() takes 0.85x with 2 parameters but 1.7x with 20 (3.7 us
against 2.2 us), since every name and value crosses to native code
and back. bench-mimetype also gains /rust variants for the C++ API.

Diff: 266 lines (+199 / -67) across 3 files Reviewer: bartlomieju Review duration: 3010m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 266 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.334
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8868"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.4% (MEDIUM) · Higher = larger blast radius
39.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.5% · Safe to merge
15.5%