Skip to content
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

Allow overriding user agent in HTTP requests #610

Closed
akirmse opened this issue Sep 2, 2021 · 2 comments
Closed

Allow overriding user agent in HTTP requests #610

akirmse opened this issue Sep 2, 2021 · 2 comments

Comments

@akirmse
Copy link

akirmse commented Sep 2, 2021

I have a RasterSource that is restricted to only certain User-Agent strings. This is a common anti-scraping measure for tiles stored on e.g. AWS. Not 100% effective, of course, but enough to keep out Web crawlers and most scripts.

I would like to set the User-Agent on HTTP requests from the Mapbox library. I do see a reference to replacing the entire HTTP stack in the Mapbox documentation (https://docs.mapbox.com/android/beta/maps/guides/migrate-to-v10/), but that's massive overkill, and anyway, this is the only reference to com.mapbox.common.HttpServiceInterface on the whole Internet, so I'm not sure that it's actually supported and used by clients.

There is a similar feature request for the Mapbox iOS SDK where it sounds like support is coming soon: mapbox/mapbox-maps-ios#435

This is easy to do in the Google Maps SDK for both Android and iOS, as the interface is a callback that lets you run arbitrary code to fetch a tile (a much preferable interface that would solve this and many other tile fetching issues).

@kiryldz
Copy link
Contributor

kiryldz commented Sep 3, 2021

Hey @akirmse!
Changes described here will land in Android at the same time as in iOS.

@kiryldz
Copy link
Contributor

kiryldz commented Sep 10, 2021

Adding interceptor landed in https://github.com/mapbox/mapbox-maps-android/releases/tag/android-v10.0.0-rc.8.

Sample code how to do that will be:

HttpServiceFactory.getInstance().setInterceptor(object : HttpServiceInterceptorInterface() {
  override fun onRequest(request: HttpRequest): HttpRequest {
    
  }

  override fun onDownload(download: DownloadOptions): DownloadOptions {
   
  }

  override fun onResponse(response: HttpResponse): HttpResponse {
    
  }
})

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

No branches or pull requests

2 participants