-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add per HTTP request callback #3597
Comments
Looking at it I might give this a try on the Android side (at least for now). But I'd like feedback on the preferred way to do this. Either
Any other suggestions? |
…jected into the HTTPContext.
@1ec5 @boundsj @friedbunny |
This would best be handled with a delegate method on iOS and not by directly exposing I'm not convinced of the need for this, however. We haven't provided such low-level networking hooks in the past and the current level of demand wouldn't appear to warrant expending much/any effort on supporting this feature. |
@jfirebaugh I'm wondering in what direction your internal discussion went regarding an interceptor API. |
Depending on the wanted direction we might be interested in helping out on this. |
Has any further consideration been given to this? |
I can see this being useful if you’re maintaining your own tile server or hosting your own styles. Unfortunately, the Mapbox team is unable to go out of our way to focus on these relatively minor use cases. A general solution would be quite complex, because the platform-specific SDK code doesn’t create these requests. Rather, the cross-platform C++ code sends these requests using an abstract interface that’s implemented further down in platform-specific adapters (such as http_file_source.mm) that don’t talk to the SDK code at all. Fortunately, for iOS, you may be able to use Foundation’s NSURLProtocol to intercept the requests and add the HTTP headers you need. I haven’t tried this approach, Mapbox doesn’t officially support it, and I don’t know if it’s OK with the App Store, but hopefully it’ll suit your needs. |
Unfortunately my use case is not driven by replacing headers, rather I need to use an entirely different HTTP library to load the tiles: http://www.reconinstruments.com/developers/develop/sample-apps-overview/web-connectivity-api/ Is there perhaps a way to fetch the generated URL of each tile to be requested, which I could then pass to this other library? |
To clarify, NSURLProtocol on iOS can be used for much more than adding headers. I can’t speak for the Android side, as I’m only familiar with iOS. But the fact that mbgl abstracts away platform networking differences may make it difficult to support what you’re asking for. I think the way to think about this problem would be intercepting requests, rather than delegating requests to client code. |
With #10948 we are allowing to set the used OkHttpClient, this allows to add interceptors. Closing. |
Nice progress! Is there something similar in the works for iOS? |
awesome, thanks @tobrun! |
Implement |
Using a custom URLProtocol doesnt work with tile requests because they use a NSURLSession. A url protocol configured with https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1411560-defaultsessionconfiguration iOS Mapbox code that uses session:
Here is my protocol:
canInit is only hit for this request: https://www.mapbox.com/ios-sdk/latest_version Thank you! |
I got this to work with method swizzling in swift. While this does work it would be preferable to not have to swizzle. For anyone else who needs this:
|
For both Android and iOS it would be nice to be able to pre process the HTTP request (okhttp3.Request and NSMutableURLRequest) before the request is sent to the webserver to be able to for example add custom headers required for your own map sources.
While at it, I think it would be a good idea to be able to construct the OkHttpClient (Android) and the NSURLSession (iOS) from custom code for similar reasons.
The text was updated successfully, but these errors were encountered: