优化网盘图片读取逻辑

优化网盘图片读取逻辑
This commit is contained in:
truewhile
2026-08-21 22:21:14 +08:00
parent cbe0d7e88f
commit 0bcb1fec87
4 changed files with 10 additions and 29 deletions
+4 -3
View File
@@ -17,7 +17,7 @@ import (
"github.com/ShukeBta/MediaStationGo/internal/config"
)
func TestImageProxyCachesFailedRemoteImageFetch(t *testing.T) {
func TestImageProxyDoesNotNegativeCacheFailedRemoteImageFetch(t *testing.T) {
var calls int32
proxy := NewImageProxy(&config.Config{Cache: config.CacheConfig{CacheDir: filepath.Join(t.TempDir(), "cache")}}, zap.NewNop())
proxy.client = &http.Client{Transport: imageRoundTripFunc(func(req *http.Request) (*http.Response, error) {
@@ -42,12 +42,13 @@ func TestImageProxyCachesFailedRemoteImageFetch(t *testing.T) {
if rec.Body.Len() != len(transparent1x1PNG) {
t.Fatalf("body length = %d, want placeholder %d", rec.Body.Len(), len(transparent1x1PNG))
}
// No negative caching: every request re-attempts upstream.
if got := rec.Header().Get("Cache-Control"); got != imagePlaceholderCacheControl {
t.Fatalf("Cache-Control = %q, want %q", got, imagePlaceholderCacheControl)
}
}
if got := atomic.LoadInt32(&calls); got != 1 {
t.Fatalf("upstream calls = %d, want 1 due to negative cache", got)
if got := atomic.LoadInt32(&calls); got != 2 {
t.Fatalf("upstream calls = %d, want 2 (one per request, no negative cache)", got)
}
}