setCustomHeadersForHost method

Future<void> setCustomHeadersForHost(
  1. String host,
  2. Map<String, String> headers
)

Sets custom HTTP headers scoped to a specific host.

The headers are attached only to requests whose URL host matches host exactly (case-insensitive); there is no subdomain or substring matching.

host is the target host, for example "tiles.example.com". headers is a map of header names to header values. Passing an empty map removes any headers previously configured for host.

Calls for different hosts accumulate; calling again for the same host replaces that host's headers. This is a process-global setting that applies to all map instances.

Throws a PlatformException if the native implementation is not available or if the operation fails.

Implementation

Future<void> setCustomHeadersForHost(
    String host, Map<String, String> headers) async {
  try {
    await _channel.invokeMethod(
        'map#setCustomHeadersForHost', {'host': host, 'headers': headers});
  } on MissingPluginException catch (e) {
    throw PlatformException(
      code: 'MISSING_IMPLEMENTATION',
      message:
          'Native implementation for setCustomHeadersForHost is not available',
      details: e.toString(),
    );
  } catch (e) {
    throw PlatformException(
      code: 'SET_HEADERS_FAILED',
      message: 'Failed to set custom headers for host',
      details: e.toString(),
    );
  }
}