Route image loading through the server User-Agent - #1091
Open
MrLinks75 wants to merge 2 commits into
Open
Conversation
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.
There was a problem hiding this comment.
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 setsUser-Agent: serverUserAgentfor image downloads. - Wires that cache manager into several
CachedNetworkImage/CachedNetworkImageProvidercall sites (widgets, screensaver, background eviction, media bar precache). - Promotes
httpfrom 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()), | ||
| ), | ||
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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