-
Notifications
You must be signed in to change notification settings - Fork 1.7k
HttpOverrides.runZoned
doesn't appear to be working correctly
#49382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
//cc @brianquinlan |
I need a response on this ASAP please, even if it's just a 'it will be a while until we fix', or a 'you're doing it wrong'! There is a very high-importance PR waiting on this. |
I tried running a scaled down version of your code in a standalone setting
This appears to run just fine, here is the output from this program
|
That's interesting. I never tried making a new client directly in the block, as it doesn't help me at all. I'll try this. If it works, I wonder if the override is being lost somehow, as the client I need to override is within another object. |
@a-siva Hi there, I've conducted some more research, and my findings are interesting. Indeed, if I use your snippet above, it does seem to work: the Therefore, I edited the 'C:\Users__\Flutter\packages\flutter\lib\src\painting_network_image_io.dart' file on my system, to add some debugging print statements. I then ran my original code - with the If I add the line If I change line 64, to add Please advise on what the issue might be, as soon as possible :). |
I am not too familiar with the flutter framework code to advice on what changes need to be made in this code to allow for overrides , adding @zanderso @jonahwilliams and @dnfield to the cc list, they are more familiar with this code and could advice you. |
HttpOverrides needs to be applied both before the NetworkImage HTTPClient is created and in the right stack. The only place that can really be done is around runApp. The location you've added HttpOverrides doesn't actually create the HttpClient or perform a request, that is done in a later even loop. If you want to extensively customize HttpClient creation you are better off creating your own ImageProvider |
Ok, that does seem to make sense, and I should've spotted it myself! I'll have to implement a custom image provider - might have some advantages for our project anyway. In that case, my only question remaining is, why is the original 'userAgent' header sent by the Many thanks for your help :) |
* Added `userAgentPackageName` implementation Improved headers implementation Deprecated `NonCachingNetworkTileProvider` in favour of `NetworkNoRetryTileProvider` Updated example pages with changes Improved documentation * Temporarily fixed multiple User-Agent headers Fixed usage of `NetworkTileProvider` Fixed deprecation notice invalid symbol reference * Removed some old TODOs Simplified `_positionedForOverlay` (solved TODO) Improved maintainability Improved documentation * Removed old deprecations (`placeholderImage` and `attributionBuilder`) * Atempt to fix `HttpOverrides` issue - unsuccessful: dart-lang/sdk#49382 (comment) * Fixed issues Added custom `ImageProvider`s Reduced reliance on 'universal_io' library Prepared for review * Fixed web platform support Seperated tile_provider.dart for web and other plaforms Removed 'universal_io' dependency Updated CHANGELOG * Fixed 'Refused to set unsafe header' error * Improved in-code documentation * Removed deprecated API remenant `attributionAlignment` from `TileLayerOptions` * Fix false positive linter warning: see https://github.com/dart-lang/linter/issues/1381 * Improved documentation Refactored base `TileProvider` into independent file
For this worked: HttpOverrides.global = _FlutterMapHTTPOverrides(); |
We were aware that this worked, but this is an unacceptable solution for a library: we shouldn't be modifying traffic outside our remit. |
Hi there,
Running
Dart SDK version: 2.17.3 (stable) (Wed Jun 1 11:06:41 2022 +0200) on "windows_x64"
Bit of background story first, might help. I am fixing an urgent issue in fleaflet/flutter_map#1292, which essentially involves adding the correct 'User-Agent' header to all HTTP requests generated by a

NetworkImage
(yes, I know this is a Flutter widget, but it doesn't matter too much I don't think).Unfortunately, just passing the 'User-Agent' through the
headers
parameter doesn't work as expected. Instead of just the specified agent, both the 'Dart/2.17 (dart:io)' and custom agent are sent in what appears to be a list:This is not acceptable, as we are not entirely sure how the backend checks the agent. Therefore, we need to only send the second/custom agent.
Unfortunately, I couldn't find an easy way to do this. It seems that using
HttpOverrides
with a customHttpClient
with the defaultuserAgent
property set tonull
is the best option.Here's the snippet that doesn't appear to be working:
Unfortunately, with the above snippet, the
createHttpClient
method never seems to be run (print
statement doesn't output anything), and both 'User-Agent's are sent, even though I only specified one.When I do this, however:
It does work, as below:

Unfortunately, this is very far from ideal, as I don't want to be changing the root zone.
Am I doing something wrong, or is the
runZoned
method not working correctly? Note that I've read all of flutter/flutter#19588, and this is not a duplicate. Many thanks for any help!The text was updated successfully, but these errors were encountered: