mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-09 02:47:29 +02:00
fix(artwork): give full-size disc art a real ETag
Regression from 04d5a556. Keying the resize cache on identity meant the
disc response no longer carried a content hash, and the full-size branch
set no ETag either — so WriteImageHeaders fell back to the empty hash
and emitted `ETag: ""` for every full-size disc image. Since ifNoneMatch
compares the unquoted value, a client echoing that back matched, and got
a 304 even after the image was replaced.
The full-size branch now carries the same identity validator the sized
branch uses, so it moves when the folder's images change.
WriteImageHeaders is hardened against the class as well: an empty
validator is no validator, so it is neither emitted nor matched.
Reported by Codex on #5847.
This commit is contained in:
parent
f4dd71d06e
commit
6bb3e98e4c
4 changed files with 48 additions and 10 deletions
|
|
@ -28,7 +28,11 @@ func WriteImageHeaders(w http.ResponseWriter, r *http.Request, img *artwork.Imag
|
|||
if etag == "" {
|
||||
etag = img.Hash
|
||||
}
|
||||
h.Set("ETag", `"`+etag+`"`)
|
||||
// An empty validator is not one: emitting it would hand every such response the same ETag,
|
||||
// and matching it would 304 a client that echoed it back even after the bytes changed.
|
||||
if etag != "" {
|
||||
h.Set("ETag", `"`+etag+`"`)
|
||||
}
|
||||
if !img.LastUpdated.IsZero() {
|
||||
h.Set("Last-Modified", img.LastUpdated.UTC().Format(http.TimeFormat))
|
||||
}
|
||||
|
|
@ -40,7 +44,7 @@ func WriteImageHeaders(w http.ResponseWriter, r *http.Request, img *artwork.Imag
|
|||
h.Set("Cache-Control", "public, no-cache")
|
||||
}
|
||||
|
||||
if ifNoneMatch(r.Header.Get("If-None-Match"), etag) {
|
||||
if etag != "" && ifNoneMatch(r.Header.Get("If-None-Match"), etag) {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ func resized() *artwork.Image {
|
|||
}
|
||||
}
|
||||
|
||||
// unvalidated stands for a response with no content hash and no representation tag.
|
||||
func unvalidated() *artwork.Image {
|
||||
return &artwork.Image{ReadCloser: io.NopCloser(strings.NewReader("IMG")), LastUpdated: lastMod}
|
||||
}
|
||||
|
||||
var _ = Describe("WriteImageHeaders", func() {
|
||||
type testCase struct {
|
||||
img *artwork.Image
|
||||
|
|
@ -101,5 +106,13 @@ var _ = Describe("WriteImageHeaders", func() {
|
|||
testCase{img: found(), ifNoneMatch: `"deadbeefdeadbeef"`, want304: false, wantCache: "public, no-cache", wantETag: `"` + testHash + `"`, wantLastMod: true}),
|
||||
Entry("placeholder ignores If-None-Match and never 304s",
|
||||
testCase{img: placeholder(), ifNoneMatch: "*", want304: false, wantCache: "no-store"}),
|
||||
|
||||
// An image with neither ETag nor Hash has no validator. Emitting one would give every
|
||||
// such response the same empty tag, and matching it would 304 changed bytes.
|
||||
Entry("omits the ETag entirely when there is no validator",
|
||||
testCase{img: unvalidated(), wantCache: "public, no-cache", wantLastMod: true}),
|
||||
Entry("never 304s an empty validator echoed back by the client",
|
||||
testCase{img: unvalidated(), ifNoneMatch: `""`, want304: false,
|
||||
wantCache: "public, no-cache", wantLastMod: true}),
|
||||
)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue