Decide a fetched image's format from its bytes once #319

Open
opened 2026-10-21 12:51:15 +02:00 by clawbot · 0 comments
Collaborator

Item 13 of 15 of #168: "Decide an input's format from its bytes once". Starts when the item before it (one file store type) is squash-merged to next.

Today (next at 989da78)

The format of a fetched image is established three times in three vocabularies: the fetcher's AllowedContentTypes check on the upstream Content-Type header (internal/httpfetcher, strings); magic.ValidateMagicBytes requiring the detected magic.MIMEType to match that header; and libvips' own detection in imageprocessor.detectFormat, which returns a plain string that formatFromString maps back to a Format. MIME strings are declared in httpfetcher, imageprocessor, magic and as literals in internal/imgcache/eviction.go, and magic.ImageFormat is a third format type beside the one #307 keeps.

Definition of done

  • The Content-Type header check stays as the cheap filter before downloading.
  • A fetched image's format is detected from its bytes once, as the one Format type of internal/imagerequest, and carried from there to the processor; libvips' detection is not mapped back through a string.
  • One function maps a Format to its MIME type, and each MIME string is declared once.
  • magic.ImageFormat, magic.MIMEType (if nothing else needs it), detectFormat's string result and formatFromString are gone.
  • An input whose format cannot be detected is an explicit error, answered as a source whose bytes do not match its Content-Type is answered today (415); nothing falls back to a default format.
  • README.md matches where it names formats or MIME types.

Approval and tests

sneak asked for each main recommendation of #168 to be its own issue, built before 1.0, one at a time in the order listed (#168 (comment)). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped.

Model: opus-5-5

Item 13 of 15 of https://git.eeqj.de/sneak/pixa/issues/168: "Decide an input's format from its bytes once". Starts when the item before it (one file store type) is squash-merged to `next`. ## Today (`next` at `989da78`) The format of a fetched image is established three times in three vocabularies: the fetcher's `AllowedContentTypes` check on the upstream `Content-Type` header (`internal/httpfetcher`, strings); `magic.ValidateMagicBytes` requiring the detected `magic.MIMEType` to match that header; and libvips' own detection in `imageprocessor.detectFormat`, which returns a plain string that `formatFromString` maps back to a `Format`. MIME strings are declared in `httpfetcher`, `imageprocessor`, `magic` and as literals in `internal/imgcache/eviction.go`, and `magic.ImageFormat` is a third format type beside the one https://git.eeqj.de/sneak/pixa/issues/307 keeps. ## Definition of done - The `Content-Type` header check stays as the cheap filter before downloading. - A fetched image's format is detected from its bytes once, as the one `Format` type of `internal/imagerequest`, and carried from there to the processor; libvips' detection is not mapped back through a string. - One function maps a `Format` to its MIME type, and each MIME string is declared once. - `magic.ImageFormat`, `magic.MIMEType` (if nothing else needs it), `detectFormat`'s string result and `formatFromString` are gone. - An input whose format cannot be detected is an explicit error, answered as a source whose bytes do not match its `Content-Type` is answered today (415); nothing falls back to a default format. - `README.md` matches where it names formats or MIME types. ## Approval and tests sneak asked for each main recommendation of https://git.eeqj.de/sneak/pixa/issues/168 to be its own issue, built before 1.0, one at a time in the order listed (https://git.eeqj.de/sneak/pixa/issues/168#issuecomment-153513). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped. Model: opus-5-5
clawbot added this to the 1.0.0 milestone 2026-10-21 12:51:15 +02:00
clawbot self-assigned this 2026-10-21 12:51:16 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#319