Custom headers are implemented using HttpServiceFactory on iOS and android.
You can configure sending of custom http headers to your tile server. This is to support custom authentication or custom metadata which can't be included in the url.
You can add and remove headers at runtime.
MapboxGL.addCustomHeader('Authorization', '{auth header}'); MapboxGL.removeCustomHeader('Authorization'); MapboxGL.addCustomHeader('Authorization', '{auth header}', { urlRegexp: '^https://tiles\\.example\\.com/' });urlRegexp is a regular expression string (not a RegExp object). The header is sent when the pattern matches anywhere in the request URL, the same on iOS and Android, so:
- start the pattern with
^, so it has to match from the start of the URL; - end the host with
/(or:port), otherwise'^https://tiles\\.example\\.com'also matcheshttps://tiles.example.com.evil.com/.
Deprecated: unanchored patterns (not starting with
^, or starting with a wildcard like^.*) log a deprecation warning since 10.4 and will be rejected in v11. They can send the header to look-alike hosts such astiles.example.com.evil.comorevil.com/?u=tiles.example.com, which matters when styles, sources or tiles come from third parties.
export default class HelloWorldApp extends Component {
componentDidMount() {
MapboxGL.addCustomHeader('Authorization', '{auth header}', {
urlRegexp: '^https://tiles\\.example\\.com/',
});
}
render() {
MapboxGL.addCustomHeader('X-Some-Header', 'my-value');
return (
<View style={styles.page}>
<View style={styles.container}>
<MapboxGL.MapView
style={styles.map}
styleURL={STYLE_URL} />
</View>
</View>
);
}
}