Skip to content

Route image loading through the server User-Agent - #1091

Open
MrLinks75 wants to merge 2 commits into
Moonfin-Client:mainfrom
MrLinks75:fix/image-cache-user-agent
Open

Route image loading through the server User-Agent#1091
MrLinks75 wants to merge 2 commits into
Moonfin-Client:mainfrom
MrLinks75:fix/image-cache-user-agent

Conversation

@MrLinks75

@MrLinks75 MrLinks75 commented Aug 9, 2026

Copy link
Copy Markdown

cached_network_image uses flutter_cache_manager's own HTTP client, separate from Dio, so it never picked up the serverUserAgent fix from d3e7a1e, reverse proxies/WAFs blocking Dart's default User-Agent still blocked posters, cast avatars, media bar art, and the screensaver even after that fix landed.
Adding a shared CacheManager (lib/util/server_image_cache.dart) that applies the same serverUserAgent, and wires it into every confirmed image call site. Only tested on media / streaming sources, was not tested on Seer / Live TV / Games /etc. Which potentially would have the same problem

Basileus added 2 commits August 9, 2026 04:43
cached_network_image uses flutter_cache_manager's own HTTP client,
completely separate from Dio, so it never picked up the serverUserAgent
fix from d3e7a1e. This adds a CacheManager subclass that applies the
same identity, ready to wire into call sites.
Covers BoundedNetworkImage, offlineAwareImageProvider (used for e.g. cast
avatars), OfflineAwareImage, media bar backdrop/logo precaching, the
background-blur image eviction path, and the screensaver. Posters loaded
fine after d3e7a1e but these paths silently failed on servers whose
WAF/reverse proxy blocks Dart's default User-Agent.
Copilot AI lite review requested due to automatic review settings August 9, 2026 02:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Routes cached_network_image/flutter_cache_manager HTTP fetches through a shared cache manager that injects the app’s server-facing User-Agent, addressing environments where reverse proxies/WAFs block Dart’s default User-Agent even after the Dio-side fix.

Changes:

  • Adds a shared CacheManager (lib/util/server_image_cache.dart) that sets User-Agent: serverUserAgent for image downloads.
  • Wires that cache manager into several CachedNetworkImage / CachedNetworkImageProvider call sites (widgets, screensaver, background eviction, media bar precache).
  • Promotes http from transitive to direct dependency.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pubspec.yaml Adds http as a direct dependency to support a custom HTTP client wrapper.
pubspec.lock Reflects http being a direct main dependency (version pinned in lockfile).
lib/util/server_image_cache.dart Introduces shared cache manager and custom http.BaseClient to apply serverUserAgent to cache-manager-driven image requests.
lib/ui/widgets/offline_aware_image.dart Routes CachedNetworkImage through the shared cache manager.
lib/ui/widgets/image_source.dart Routes offlineAwareImageProvider’s CachedNetworkImageProvider through the shared cache manager.
lib/ui/widgets/bounded_network_image.dart Routes both provider-based precache and widget rendering through the shared cache manager.
lib/ui/screensaver/screensaver_view.dart Routes screensaver precache and displayed images through the shared cache manager.
lib/data/services/background_service.dart Ensures eviction targets match providers created with the shared cache manager.
lib/data/repositories/media_bar_repository.dart Routes media bar image precaching through the shared cache manager.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +21 to +30
class _ServerUserAgentHttpClient extends http.BaseClient {
_ServerUserAgentHttpClient(this._inner);
final http.Client _inner;

@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
request.headers['User-Agent'] = serverUserAgent;
return _inner.send(request);
}
}
Comment on lines +12 to +18
final serverImageCacheManager = CacheManager(
Config(
'moonfinServerImageCache',
fileService: HttpFileService(
httpClient: _ServerUserAgentHttpClient(http.Client()),
),
),
Comment on lines +12 to +18
final serverImageCacheManager = CacheManager(
Config(
'moonfinServerImageCache',
fileService: HttpFileService(
httpClient: _ServerUserAgentHttpClient(http.Client()),
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants