GitHub 0
Skip to content

Negotiation

The seven rules that pick a form from a twin URL, ?format= and Accept, and what Claude Code, Cursor, Codex and curl get from each.

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.

  • For a media type, the range that applies is the most specific one in Accept: the exact type, then type/*, 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 Accept counts 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 handle offers html, then markdown. A route that calls respond offers its keys.
  1. A twin URL, or ?format= naming an offered form, reduces the offers to that form. The twin is checked first.
  2. Among offered forms with a named type, the highest q wins. On equal q, the type listed first in Accept wins.
  3. If no offered form is named, the first offered form with a permitted type wins. A wildcard permits and never prefers.
  4. If nothing offered is permitted, the pick is the first offer and acceptable is false.
  5. The media type sent is the named type that won, else the form's first permitted type, else its first type.
  6. 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.
  7. Every response whoasks shapes, and every HTML response that passes through handle, carries Vary with the entries of ask.vary.

For a page that offers html then markdown:

AcceptPickRule
*/*html3. Nothing is named, the first offer is permitted
text/*html3. A wildcard does not prefer Markdown
text/markdown, text/htmlmarkdown2. Equal q, Markdown is listed first
text/html, text/markdownhtml2. Equal q, HTML is listed first
text/html;q=0.5, text/markdown;q=0.8markdown2. Highest q
*/*;q=1, text/markdown;q=0.5markdown2. A named type beats a wildcard, whatever its q
text/html;q=0, */*markdown3. HTML is refused, */* permits Markdown
text/plainmarkdown, sent as text/plain5. The named type is sent
text/x-markdownmarkdown, sent as text/x-markdown5
image/pnghtml, acceptable: false4
application/jsonhtml, acceptable: false4. A page does not offer JSON

On equal q, the order in Accept decides, not the order of the offers.

  • A twin is the canonical path plus a form's ext. Only markdown has one built in, .md.
  • /index.md is 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 html and json, /README.md is an ordinary path.
  • ?format= takes a form's name or its ext without the dot, exactly as written: md, markdown, html, json. Only offered forms count. Any other value stays in the URL for the app.
  • ask.url is the URL without the suffix and without format. Other query parameters stay.
  • An override still checks Accept. /docs/guide.md with Accept: text/html picks markdown with acceptable: false. handle answers it with Markdown anyway. A strict respond answers 406.

handle sends the first offer and never refuses. respond sends the first offer too, unless the site is strict. See Refuse with 406.

  • ask.vary starts 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 Vary the app already set. Vary: Cookie, accept stays as it is.
  • A response that passes through handle untouched, such as an image or a plain JSON route, gets no Vary.

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.

ClientAcceptPagePage .md twin or ?format=mdAPI route
Claude Code WebFetchtext/markdown, text/html, */*text/markdowntext/markdowntext/markdown
Cursortext/markdown,text/html;q=0.9,application/xhtml+xml;q=0.8,application/xml;q=0.7,image/webp;q=0.6,*/*;q=0.5text/markdowntext/markdowntext/markdown
Codextext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8text/htmltext/markdownapplication/json
curl*/*text/htmltext/markdownapplication/json
Synthetictext/plaintext/plain, Markdowntext/plain, Markdowntext/plain, the agent text
Syntheticapplication/jsontext/htmltext/markdownapplication/json
HeaderSource
Claude CodeCaptured by us from Claude Code's WebFetch, 6 December 2026
curlcurl's default, captured by us, 6 December 2026
CodexFrom PostHog/posthog.com#21381. Not captured by us
CursorUnverified. A summary of Checkly's February 2026 article. Not captured by us
The two synthetic rowsNo client is known to send them. They exercise the rules

test/clients.ts in the repository lists each header with its source.

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.

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"] }
ts

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"]).

reasonWhen
twinThe path ended with a form's ext
query?format= named an offered form
acceptAccept named the picked type, or refused the first offer so a later one won
defaultThe pick is the first offer and Accept did not name its type. Also when nothing was acceptable
layerA hook changed the form or the type