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
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// TestFormatAutoVaryNextToOrigin requests an image URL with the format auto
|
|
// through the server's routes and verifies that the answer carries
|
|
// Vary: Accept next to the Vary: Origin the CORS middleware sends.
|
|
func TestFormatAutoVaryNextToOrigin(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
source := encodeTestPNG(t, 64, 48)
|
|
|
|
upstream := httptest.NewServer(http.HandlerFunc(
|
|
func(w http.ResponseWriter, _ *http.Request) {
|
|
w.Header().Set("Content-Type", "image/png")
|
|
_, _ = w.Write(source)
|
|
}))
|
|
t.Cleanup(upstream.Close)
|
|
|
|
s, _, _ := startImageProxy(t, upstream)
|
|
|
|
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet,
|
|
"/v1/image/"+upstreamHost+"/photo.png/32x24.auto", nil)
|
|
req.Header.Set("Origin", "https://app.example.com")
|
|
req.Header.Set("Accept", "image/webp")
|
|
|
|
rec := httptest.NewRecorder()
|
|
s.ServeHTTP(rec, req)
|
|
|
|
vary := rec.Header().Values("Vary")
|
|
t.Logf("status %d, Content-Type %s, Vary %v",
|
|
rec.Code, rec.Header().Get("Content-Type"), vary)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
|
|
}
|
|
|
|
if want := []string{"Origin", "Accept"}; !slices.Equal(vary, want) {
|
|
t.Errorf("Vary = %v, want %v", vary, want)
|
|
}
|
|
}
|