One handler body and one error mapping for the two image routes #316

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

Item 10 of 15 of #168: "One handler body for the two image routes". Starts when the item before it (deriving every key in one place) is squash-merged to next.

Today (next at 989da78)

HandleImage (internal/handlers/image.go) and HandleImageEnc (internal/handlers/imageenc.go) each get the image, set headers, answer If-None-Match and HEAD, copy and log, and map errors with two different functions, respondImageError and handleImageError, which disagree: for example, handleImageError maps httpfetcher.ErrUpstreamTimeout and respondImageError logs at a different level first.

Definition of done

  • The two routes differ only in how they obtain the request and its expiry: /v1/image/ parses the path and verifies the signature, /v1/e/ decrypts the token. Both then call one function that serves the image (headers, ETag and 304, HEAD, the copy, the log line).
  • One error mapping serves both routes. Where the two mappings answer differently today, the route-independent answer is the one already documented in README.md's route tables; the PR body lists each status or log level that changes, in one line each.
  • A test runs the same error cases through both routes and asserts the same status for each.
  • README.md's route tables match.

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; a test that pins one route's answer that differs from the shared answer moves to the shared answer and is named in the PR body; no other assertion is weakened or dropped.

Model: opus-5-5

Item 10 of 15 of https://git.eeqj.de/sneak/pixa/issues/168: "One handler body for the two image routes". Starts when the item before it (deriving every key in one place) is squash-merged to `next`. ## Today (`next` at `989da78`) `HandleImage` (`internal/handlers/image.go`) and `HandleImageEnc` (`internal/handlers/imageenc.go`) each get the image, set headers, answer `If-None-Match` and `HEAD`, copy and log, and map errors with two different functions, `respondImageError` and `handleImageError`, which disagree: for example, `handleImageError` maps `httpfetcher.ErrUpstreamTimeout` and `respondImageError` logs at a different level first. ## Definition of done - The two routes differ only in how they obtain the request and its expiry: `/v1/image/` parses the path and verifies the signature, `/v1/e/` decrypts the token. Both then call one function that serves the image (headers, `ETag` and 304, `HEAD`, the copy, the log line). - One error mapping serves both routes. Where the two mappings answer differently today, the route-independent answer is the one already documented in `README.md`'s route tables; the PR body lists each status or log level that changes, in one line each. - A test runs the same error cases through both routes and asserts the same status for each. - `README.md`'s route tables match. ## 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; a test that pins one route's answer that differs from the shared answer moves to the shared answer and is named in the PR body; no other assertion is weakened or dropped. Model: opus-5-5
clawbot added this to the 1.0.0 milestone 2026-10-21 12:50:47 +02:00
clawbot self-assigned this 2026-10-21 12:50:48 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#316