whoasks makes one pick per request: a form and a media type. The rules below run in the same order every time. site.ask(request) returns the pick.
Three words
Section titled "Three words"- For a media type, the range that applies is the most specific one in
Accept: the exact type, thentype/*, then*/*. - A type is named when an exact range lists it with q above 0.
- A type is permitted when the range that applies has q above 0.
- A missing, empty, or unreadable
Acceptcounts as*/*. A range with a malformed type or q is dropped. - A route's offers are the forms it can produce, in order. A page behind
handleoffershtml, thenmarkdown. A route that callsrespondoffers its keys.
The rules
Section titled "The rules"- A twin URL, or
?format=naming an offered form, reduces the offers to that form. The twin is checked first. - Among offered forms with a named type, the highest q wins. On equal q, the type listed first in
Acceptwins. - If no offered form is named, the first offered form with a permitted type wins. A wildcard permits and never prefers.
- If nothing offered is permitted, the pick is the first offer and
acceptableis false. - The media type sent is the named type that won, else the form's first permitted type, else its first type.
- The hooks of the layers run last, in layer order. A hook cannot pick a form or a type the request did not allow. See Change the pick.
- Every response whoasks shapes, and every HTML response that passes through
handle, carriesVarywith the entries ofask.vary.
Examples
Section titled "Examples"For a page that offers html then markdown:
Accept | Pick | Rule |
|---|---|---|
*/* | html | 3. Nothing is named, the first offer is permitted |
text/* | html | 3. A wildcard does not prefer Markdown |
text/markdown, text/html | markdown | 2. Equal q, Markdown is listed first |
text/html, text/markdown | html | 2. Equal q, HTML is listed first |
text/html;q=0.5, text/markdown;q=0.8 | markdown | 2. Highest q |
*/*;q=1, text/markdown;q=0.5 | markdown | 2. A named type beats a wildcard, whatever its q |
text/html;q=0, */* | markdown | 3. HTML is refused, */* permits Markdown |
text/plain | markdown, sent as text/plain | 5. The named type is sent |
text/x-markdown | markdown, sent as text/x-markdown | 5 |
image/png | html, acceptable: false | 4 |
application/json | html, acceptable: false | 4. A page does not offer JSON |
On equal q, the order in Accept decides, not the order of the offers.
URL overrides
Section titled "URL overrides"- A twin is the canonical path plus a form's
ext. Onlymarkdownhas one built in,.md. /index.mdis the twin of/. A path that is only the suffix, such as/docs/.md, is not a twin.- A twin of a form the route does not offer is not a twin. On a route offering
htmlandjson,/README.mdis an ordinary path. ?format=takes a form's name or itsextwithout the dot, exactly as written:md,markdown,html,json. Only offered forms count. Any other value stays in the URL for the app.ask.urlis the URL without the suffix and withoutformat. Other query parameters stay.- An override still checks
Accept./docs/guide.mdwithAccept: text/htmlpicksmarkdownwithacceptable: false.handleanswers it with Markdown anyway. A strictrespondanswers 406.
Nothing acceptable
Section titled "Nothing acceptable"handle sends the first offer and never refuses. respond sends the first offer too, unless the site is strict. See Refuse with 406.
ask.varystarts as["Accept"].- A hook that reads another header adds it, as the Codex layer adds
User-Agent. - whoasks appends each name once and keeps a
Varythe app already set.Vary: Cookie, acceptstays as it is. - A response that passes through
handleuntouched, such as an image or a plain JSON route, gets noVary.
What real clients get
Section titled "What real clients get"The table is the conformance matrix in test/conformance.test.ts, which runs every row against site.handle and against an h3 app. "Page" is a page behind handle. "API route" calls respond with json then markdown.
| Client | Accept | Page | Page .md twin or ?format=md | API route |
|---|---|---|---|---|
| Claude Code WebFetch | text/markdown, text/html, */* | text/markdown | text/markdown | text/markdown |
| Cursor | text/markdown,text/html;q=0.9,application/xhtml+xml;q=0.8,application/xml;q=0.7,image/webp;q=0.6,*/*;q=0.5 | text/markdown | text/markdown | text/markdown |
| Codex | text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 | text/html | text/markdown | application/json |
| curl | */* | text/html | text/markdown | application/json |
| Synthetic | text/plain | text/plain, Markdown | text/plain, Markdown | text/plain, the agent text |
| Synthetic | application/json | text/html | text/markdown | application/json |
Where the headers come from
Section titled "Where the headers come from"| Header | Source |
|---|---|
| Claude Code | Captured by us from Claude Code's WebFetch, 6 December 2026 |
| curl | curl's default, captured by us, 6 December 2026 |
| Codex | From PostHog/posthog.com#21381. Not captured by us |
| Cursor | Unverified. A summary of Checkly's February 2026 article. Not captured by us |
| The two synthetic rows | No client is known to send them. They exercise the rules |
test/clients.ts in the repository lists each header with its source.
Codex and twin URLs
Section titled "Codex and twin URLs"Codex sends a browser-like Accept, so on a page it gets HTML, and on a twin URL it gets text/markdown through */*.
The README reports that Codex's fetch tool rejects text/markdown. We did not capture that ourselves.
Accept alone cannot tell Codex from a browser, and whoasks does not read the User-Agent. A layer that reads the User-Agent sends text/plain to it instead. See Change the pick for the code.
Read the pick
Section titled "Read the pick"const ask = site.ask(request);
// GET /docs/guide.md, Accept: */*
// { form: "markdown", type: "text/markdown", reason: "twin", acceptable: true,
// url: URL "https://example.com/docs/guide", vary: ["Accept"] }ask is synchronous and builds no response.
With no second argument, it uses the page offers. Pass the offers of a route to ask for that route: site.ask(request, ["json", "markdown"]).
reason | When |
|---|---|
twin | The path ended with a form's ext |
query | ?format= named an offered form |
accept | Accept named the picked type, or refused the first offer so a later one won |
default | The pick is the first offer and Accept did not name its type. Also when nothing was acceptable |
layer | A hook changed the form or the type |