Take the signature, the expiry and the URL scheme off the image request (closes #314)
check / check (push) Canceled after 0s

The image request now holds only its source and its transform, exactly what
the variant key covers. The /v1/image/ handler checks the allowlist and
verifies the signature itself with Signer.Verify(req, sig, expires). Both
image handlers keep the URL's expiry as a local value for Cache-Control. The
image service holds no signer, allowlist or AllowHTTP, and ValidateRequest is
gone. The fetcher takes the source and builds its URL with Source.URL from its
own AllowHTTP, so no URL string is built and parsed again. chooseAutoFormat
returns the format it chooses instead of writing into the request. The signed
URL format and every route's answers are unchanged.

Model: opus-5-5
This commit is contained in:
2026-10-26 11:54:15 +00:00
parent 63690a9ec9
commit 08028e4560
45 changed files with 729 additions and 884 deletions
@@ -2,57 +2,49 @@ package imagerequest
import "testing"
func TestRequest_SourceURL_DefaultHTTPS(t *testing.T) {
func TestSource_URL_DefaultHTTPS(t *testing.T) {
t.Parallel()
req := &Request{
Source: Source{
Host: testHostCDN,
Path: testPathCat,
Query: "v=2",
},
source := Source{
Host: testHostCDN,
Path: testPathCat,
Query: "v=2",
}
got := req.SourceURL()
got := source.URL(false).String()
want := "https://cdn.example.com/photos/cat.jpg?v=2"
if got != want {
t.Errorf("SourceURL() = %q, want %q", got, want)
t.Errorf("URL() = %q, want %q", got, want)
}
}
func TestRequest_SourceURL_AllowHTTP(t *testing.T) {
func TestSource_URL_AllowHTTP(t *testing.T) {
t.Parallel()
req := &Request{
Source: Source{
Host: "localhost:8080",
Path: testPathCat,
},
AllowHTTP: true,
source := Source{
Host: "localhost:8080",
Path: testPathCat,
}
got := req.SourceURL()
got := source.URL(true).String()
want := "http://localhost:8080/photos/cat.jpg"
if got != want {
t.Errorf("SourceURL() = %q, want %q", got, want)
t.Errorf("URL() = %q, want %q", got, want)
}
}
func TestRequest_SourceURL_AllowHTTPFalse(t *testing.T) {
func TestSource_URL_AllowHTTPFalse(t *testing.T) {
t.Parallel()
req := &Request{
Source: Source{
Host: testHostCDN,
Path: "/img.jpg",
},
AllowHTTP: false,
source := Source{
Host: testHostCDN,
Path: "/img.jpg",
}
got := req.SourceURL()
got := source.URL(false).String()
if got != "https://cdn.example.com/img.jpg" {
t.Errorf("SourceURL() = %q, want https scheme", got)
t.Errorf("URL() = %q, want https scheme", got)
}
}