MapboxHttpService class
Configures the HTTP requests of the Mapbox SDK.
The settings apply only to the requests that the Mapbox SDK sends: the requests of all maps, and on Android and iOS also offline downloads. Other HTTP requests of your app do not change. Use MapboxHttpService.instance. A map is not necessary, so you can set headers before the first map loads its style.
Call WidgetsFlutterBinding.ensureInitialized() before you use the
service in main.
await MapboxHttpService.instance.setCustomHeadersForHost(
'tiles.example.com',
{'Authorization': 'Basic $credentials'},
);
On web, the browser applies CORS to requests with custom headers:
- The server must allow the custom headers in its CORS response
(
Access-Control-Allow-Headers). Each new URL with custom headers causes one extra preflight request. - The CORS response of the Mapbox tile endpoints (
api.mapbox.com/v4) does not allow custom headers, so the browser blocks these tile requests if they have custom headers. Set custom headers only for your own hosts. Android and iOS do not apply CORS, so the same headers work there.
On all platforms, a header change does not reload the tiles that are already in the cache.
Constructors
- MapboxHttpService(MapboxHttpServicePlatformInterface _impl)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clearCustomHeaders(
) → Future< void> - Removes all custom headers previously configured via setCustomHeadersForHost.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setCustomHeadersForHost(
String host, Map< String, String> headers) → Future<void> -
Sets custom HTTP headers scoped to a specific
host. -
setMaxRequestsPerHost(
int max) → Future< void> - Sets the maximum number of concurrent HTTP requests per host that the underlying HTTP service may issue.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → MapboxHttpService
-
The process-wide HTTP service.
final