Implement format=auto (Accept-header content negotiation) #88
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Verified against
mainat61f42e6. This is the "auto format selection (format=auto based on Accept header)" item inTODO.md; confirmed missing —parseFormat(internal/imgcache/urlparser.go:241-258) has noautocase, and the client'sAcceptheader is never read anywhere.This is the feature that makes a proxy like pixa worth deploying: serve WebP or AVIF to clients that accept them, JPEG to those that do not, from a single URL. Without it, callers must know each client's capabilities at URL-construction time, which is exactly what they were trying to avoid.
Definition of done
format=autoselects the best format the client accepts, preferring AVIF, then WebP, then falling back to the source format (or JPEG). The preference order is documented.Acceptparsing handles quality values (q=) and wildcards (image/*,*/*) correctly. A client sending noAcceptgets the fallback.Vary: Acceptis set on every negotiated response. Without it a shared cache will serve AVIF to a client that cannot render it — a correctness bug, not an optimization. See the related response-headers issue.auto, so negotiated variants do not collide.format, so a URL signed forautomust validate againstauto(the literal requested value) rather than the resolved one — otherwise the signature depends on the client's headers and becomes unverifiable. Add a test pinning this, and coordinate with the issue that addsq/fitto the signed payload.format=automust never silently produce a format the client explicitly rejected. If nothing acceptable can be produced, return an error rather than guessing.Acceptvalues: AVIF-capable, WebP-capable, neither, wildcard-only, absent, and a malformed header.autoin the format list.make checkgreen.