setCustomHeaders method
- @Deprecated('Headers set this way are attached to every host the map fetches from, ' 'including third-party hosts, which can leak credentials. Use ' 'setCustomHeadersForHost to scope headers to a specific host.')
Sets custom HTTP headers that are attached to every request the map makes, regardless of host.
Warning: these headers are not restricted to Mapbox hosts — they are attached to every outgoing request, including requests to third-party hosts referenced by styles, sources, sprites, glyphs and tiles. Placing a credential here can therefore leak it to hosts you do not control.
Use setCustomHeadersForHost to attach headers to a specific host only.
headers is a map of header names to header values. Pass an empty map to
clear previously set global headers.
Throws a PlatformException if the native implementation is not available or if the operation fails.
Implementation
@Deprecated(
'Headers set this way are attached to every host the map fetches from, '
'including third-party hosts, which can leak credentials. Use '
'setCustomHeadersForHost to scope headers to a specific host.')
Future<void> setCustomHeaders(Map<String, String> headers) async {
try {
await _channel.invokeMethod('map#setCustomHeaders', {'headers': headers});
} on MissingPluginException catch (e) {
throw PlatformException(
code: 'MISSING_IMPLEMENTATION',
message: 'Native implementation for setCustomHeaders is not available',
details: e.toString(),
);
} catch (e) {
throw PlatformException(
code: 'SET_HEADERS_FAILED',
message: 'Failed to set custom headers',
details: e.toString(),
);
}
}