You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @property {string} type Response body type to be returned `'string' | 'json' | 'arrayBuffer'`.
39
-
* @property {string} credentials `'same-origin'|'include'` Use 'include' to send cookies with cross-origin requests.
40
-
* @property {boolean} collectResourceTiming If true, Resource Timing API information will be collected for these transformed requests and returned in a resourceTiming property of relevant data events.
41
-
* @property {string} referrerPolicy A string representing the request's referrerPolicy. For more information and possible values, see the [Referrer-Policy HTTP header page](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy).
51
+
* @property {Object} [headers] The headers to be sent with the request.
52
+
* @property {string} [method='GET'] Request method, one of `'GET' | 'POST' | 'PUT'`.
53
+
* @property {string} [body] Request body.
54
+
* @property {string} [type='string'] Response body type to be returned, one of `'string' | 'json' | 'arrayBuffer'`.
55
+
* @property {string} [credentials] Cross-origin credentials mode, one of `'same-origin' | 'include'`. Use `'include'` to send cookies with cross-origin requests.
56
+
* @property {boolean} [collectResourceTiming=false] If `true`, Resource Timing API information will be collected for these transformed requests and returned in a `resourceTiming` property of relevant `data` events.
57
+
* @property {string} [referrerPolicy] A string representing the request's referrerPolicy. For more information and possible values, see the [Referrer-Policy HTTP header page](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy).
58
+
* @see {@link RequestTransformFunction}
59
+
* @see {@link ResourceType}
60
+
*/
61
+
exporttypeRequestParameters={
62
+
url: string;
63
+
headers?: Record<string,string>;
64
+
method?: 'GET'|'POST'|'PUT';
65
+
body?: string;
66
+
type?: 'string'|'json'|'arrayBuffer';
67
+
credentials?: 'same-origin'|'include';
68
+
collectResourceTiming?: boolean;
69
+
referrerPolicy?: ReferrerPolicy;
70
+
};
71
+
72
+
/**
73
+
* A callback run before the Map makes a request for an external URL, used to rewrite the URL, attach headers, or set the credentials property for cross-origin requests.
74
+
* The callback may return a {@link RequestParameters} object synchronously, or a `Promise` that resolves to one when the parameters need to be computed asynchronously — useful when each request needs a credential that has to be fetched at runtime, such as a [temporary access token](https://docs.mapbox.com/api/accounts/tokens/#create-a-temporary-token).
75
+
*
76
+
* @callback RequestTransformFunction
77
+
* @param {string} url The URL to be requested.
78
+
* @param {ResourceType} [resourceType] The type of resource being requested.
79
+
* @param {Object} [options] Options including an `AbortSignal` that will be aborted if the request is cancelled.
80
+
* @param {AbortSignal} [options.signal] An `AbortSignal` that will be aborted if the request is cancelled. Pass this to any async work (e.g. a `fetch` call) inside the callback so that the work is cancelled together with the request.
81
+
* @returns {RequestParameters | Promise<RequestParameters>} The modified request parameters, or a `Promise` that resolves to them.
82
+
*
42
83
* @example
43
-
* // use transformRequest to modify requests that begin with `http://myHost`
44
-
* const map = new Map({
84
+
* const map = new mapboxgl.Map({
45
85
* container: 'map',
46
-
* style: 'mapbox://styles/mapbox/streets-v11',
86
+
* style: 'mapbox://styles/mapbox/standard',
47
87
* transformRequest: (url, resourceType) => {
48
-
* if (resourceType === 'Source' && url.indexOf('http://myHost') > -1) {
88
+
* // Use `transformRequest` to modify requests that begin with `http://myHost`.
89
+
* if (resourceType === 'Source' && url.startsWith('http://myHost')) {
49
90
* return {
50
91
* url: url.replace('http', 'https'),
51
92
* headers: {'my-custom-header': true},
52
-
* credentials: 'include' // Include cookies for cross-origin requests
0 commit comments