Serve the format auto, chosen from the Accept header (closes #88) #220

Merged
clawbot merged 2 commits from issue-88-format-auto into next 2026-10-05 05:24:51 +02:00
Collaborator

Adds the format auto for /v1/image/ URLs, encrypted URLs and the generator page, per the plan on #88.

Once the signature or token is checked, pixa chooses AVIF when Accept names image/avif, else WebP when it names image/webp, else JPEG when the most specific of image/jpeg, image/* and */* allows it, or when there is no Accept. q=0 refuses a format. A header allowing none of the three answers 406; one that does not parse, or has a q outside 0 to 1, answers 400. The signature and token cover the literal auto; the cache key and ETag use the chosen format, so the formats are cached apart. Answers from that point on, 304 and HEAD included, carry Vary: Accept next to the CORS Vary: Origin; fixed-format answers do not. README.md documents the order.

Each Accept entry is parsed with the standard library's mime.ParseMediaType: no Go library for this is both widely used and maintained, and the most used one ignores q=0.

  • Deviation from the plan: image/* and */* do not make AVIF or WebP acceptable; only naming them does, because browsers that cannot show them (Safari 14 and 15 for AVIF, older Safari and Firefox for WebP) send the wildcards too. Wildcards still allow and refuse JPEG.
  • Judgement call: a malformed Accept answers 400 rather than being ignored, per the repo rule against silent fallbacks.
  • Judgement call: q values above 0 do not reorder the three formats.
  • Judgement call: an encrypted auto URL ends in img.jpg, as orig does.

Model: opus-5-5

Adds the format `auto` for `/v1/image/` URLs, encrypted URLs and the generator page, per the plan on https://git.eeqj.de/sneak/pixa/issues/88. Once the signature or token is checked, pixa chooses AVIF when `Accept` names `image/avif`, else WebP when it names `image/webp`, else JPEG when the most specific of `image/jpeg`, `image/*` and `*/*` allows it, or when there is no `Accept`. `q=0` refuses a format. A header allowing none of the three answers 406; one that does not parse, or has a `q` outside 0 to 1, answers 400. The signature and token cover the literal `auto`; the cache key and `ETag` use the chosen format, so the formats are cached apart. Answers from that point on, 304 and `HEAD` included, carry `Vary: Accept` next to the CORS `Vary: Origin`; fixed-format answers do not. `README.md` documents the order. Each `Accept` entry is parsed with the standard library's `mime.ParseMediaType`: no Go library for this is both widely used and maintained, and the most used one ignores `q=0`. - Deviation from the plan: `image/*` and `*/*` do not make AVIF or WebP acceptable; only naming them does, because browsers that cannot show them (Safari 14 and 15 for AVIF, older Safari and Firefox for WebP) send the wildcards too. Wildcards still allow and refuse JPEG. - Judgement call: a malformed `Accept` answers 400 rather than being ignored, per the repo rule against silent fallbacks. - Judgement call: `q` values above 0 do not reorder the three formats. - Judgement call: an encrypted `auto` URL ends in `img.jpg`, as `orig` does. Model: opus-5-5
clawbot added the needs-review label 2026-10-05 04:50:58 +02:00
clawbot self-assigned this 2026-10-05 04:50:58 +02:00
clawbot added 2 commits 2026-10-05 04:50:58 +02:00
Tests for #88, before the change:
the format chosen for each Accept header (AVIF-capable, WebP-only,
neither, wildcard only, absent, q=0 on AVIF, malformed), both image
routes serving an auto URL in the chosen format with Vary: Accept, also
on HEAD and 304, the signature covering auto rather than the chosen
format, each chosen format cached apart, and Vary: Accept next to the
CORS middleware's Vary: Origin. They do not compile yet: FormatAuto and
formatForAccept do not exist.

Model: opus-5-5
auto is a format in the /v1/image/ path, an encrypted URL's token and
the generator page. Once the signature or token is checked, pixa
chooses AVIF when Accept names image/avif, else WebP when it names
image/webp, else JPEG when the most specific of image/jpeg, image/* and
*/* allows it or Accept is absent. q=0 refuses a format; a header
allowing none of the three answers 406, one that does not parse 400.
The signature and token cover auto itself; the cache key and ETag use
the chosen format. Answers from then on carry Vary: Accept.

Model: opus-5-5
Author
Collaborator

PASS 9a5ef06c804b89d0972eec94fee69d7f94ea548e, rebased onto next at 01823d27dba433d4412b7446cff2d56e224bb01d.

Model: opus-5-5

**PASS** `9a5ef06c804b89d0972eec94fee69d7f94ea548e`, rebased onto `next` at `01823d27dba433d4412b7446cff2d56e224bb01d`. Model: opus-5-5
clawbot merged commit 15d95436a5 into next 2026-10-05 05:24:51 +02:00
clawbot deleted branch issue-88-format-auto 2026-10-05 05:24:51 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#220