Serve the format auto, chosen from the Accept header (closes #88)
check / check (push) Failing after 3s

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
This commit was merged in pull request #220.
This commit is contained in:
2026-10-05 05:24:50 +02:00
parent 01823d27db
commit 15d95436a5
12 changed files with 560 additions and 14 deletions
+5
View File
@@ -22,6 +22,11 @@ const (
FormatWebP ImageFormat = "webp"
FormatAVIF ImageFormat = "avif"
FormatGIF ImageFormat = "gif"
// FormatAuto stands for AVIF, WebP or JPEG, chosen for each request
// from its Accept header once the URL's signature or token has been
// checked; it is never processed or cached as itself.
FormatAuto ImageFormat = "auto"
)
// Size represents requested image dimensions
+2
View File
@@ -277,6 +277,8 @@ func parseFormat(s string) (ImageFormat, error) {
return FormatAVIF, nil
case "gif":
return FormatGIF, nil
case "auto":
return FormatAuto, nil
default:
return "", fmt.Errorf("%w: %s", ErrInvalidFormat, s)
}
@@ -111,6 +111,21 @@ func TestParseImageURL(t *testing.T) {
}
}
// TestParseImageURL_AutoFormat verifies that the format auto in an image URL
// parses as FormatAuto.
func TestParseImageURL_AutoFormat(t *testing.T) {
t.Parallel()
got, err := ParseImageURL("/v1/image/example.com/photo.jpg/200x200.auto")
if err != nil {
t.Fatalf("ParseImageURL() error = %v", err)
}
if got.Format != FormatAuto {
t.Errorf("Format = %q, want %q", got.Format, FormatAuto)
}
}
func TestParseImageURL_Errors(t *testing.T) {
t.Parallel()