imageproxy
imageproxy copied to clipboard
Treat empty cache objects as misses to prevent poisoning
When using S3 or GCS cache with bucket lifecycle rules to automatically delete old objects, imageproxy can get "poisoned" with empty cache entries. This happens because the cache returns empty data ([]byte{}, true) instead of a cache miss (nil, false), causing httpcache to serve blank responses.
This PR fixes the issue by treating zero-length objects as cache misses in both S3 and GCS cache implementations.
- Add empty object check in
s3cache.Get()andgcscache.Get() - Refactor S3 cache to use
s3iface.S3APIinterface for testability - Refactor GCS cache to use custom interfaces for testability (bit verbose; mirrors the S3 approach)
- Add
NewWithClient/NewWithBucketconstructors for dependency injection - Add comprehensive test coverage for both cache implementations, necessary to confirm expected behavior when a cache object is deleted
Fixes #248
/cc @Ladybiss @mdkent