axios 1.6.7 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/index.d.cts CHANGED
@@ -268,7 +268,8 @@ declare namespace axios {
268
268
  | 'document'
269
269
  | 'json'
270
270
  | 'text'
271
- | 'stream';
271
+ | 'stream'
272
+ | 'formdata';
272
273
 
273
274
  type responseEncoding =
274
275
  | 'ascii' | 'ASCII'
@@ -353,11 +354,12 @@ declare namespace axios {
353
354
  upload?: boolean;
354
355
  download?: boolean;
355
356
  event?: BrowserProgressEvent;
357
+ lengthComputable: boolean;
356
358
  }
357
359
 
358
360
  type Milliseconds = number;
359
361
 
360
- type AxiosAdapterName = 'xhr' | 'http' | string;
362
+ type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
361
363
 
362
364
  type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
363
365
 
@@ -415,6 +417,7 @@ declare namespace axios {
415
417
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
416
418
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
417
419
  withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
420
+ fetchOptions?: Record<string, any>;
418
421
  }
419
422
 
420
423
  // Alias
package/index.d.ts CHANGED
@@ -209,7 +209,8 @@ export type ResponseType =
209
209
  | 'document'
210
210
  | 'json'
211
211
  | 'text'
212
- | 'stream';
212
+ | 'stream'
213
+ | 'formdata';
213
214
 
214
215
  export type responseEncoding =
215
216
  | 'ascii' | 'ASCII'
@@ -294,11 +295,12 @@ export interface AxiosProgressEvent {
294
295
  upload?: boolean;
295
296
  download?: boolean;
296
297
  event?: BrowserProgressEvent;
298
+ lengthComputable: boolean;
297
299
  }
298
300
 
299
301
  type Milliseconds = number;
300
302
 
301
- type AxiosAdapterName = 'xhr' | 'http' | string;
303
+ type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
302
304
 
303
305
  type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
304
306
 
@@ -356,6 +358,7 @@ export interface AxiosRequestConfig<D = any> {
356
358
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
357
359
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
358
360
  withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
361
+ fetchOptions?: Record<string, any>;
359
362
  }
360
363
 
361
364
  // Alias
@@ -1,11 +1,13 @@
1
1
  import utils from '../utils.js';
2
2
  import httpAdapter from './http.js';
3
3
  import xhrAdapter from './xhr.js';
4
+ import fetchAdapter from './fetch.js';
4
5
  import AxiosError from "../core/AxiosError.js";
5
6
 
6
7
  const knownAdapters = {
7
8
  http: httpAdapter,
8
- xhr: xhrAdapter
9
+ xhr: xhrAdapter,
10
+ fetch: fetchAdapter
9
11
  }
10
12
 
11
13
  utils.forEach(knownAdapters, (fn, value) => {
@@ -0,0 +1,229 @@
1
+ import platform from "../platform/index.js";
2
+ import utils from "../utils.js";
3
+ import AxiosError from "../core/AxiosError.js";
4
+ import composeSignals from "../helpers/composeSignals.js";
5
+ import {trackStream} from "../helpers/trackStream.js";
6
+ import AxiosHeaders from "../core/AxiosHeaders.js";
7
+ import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
8
+ import resolveConfig from "../helpers/resolveConfig.js";
9
+ import settle from "../core/settle.js";
10
+
11
+ const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
12
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
13
+
14
+ // used only inside the fetch adapter
15
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
16
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
17
+ async (str) => new Uint8Array(await new Response(str).arrayBuffer())
18
+ );
19
+
20
+ const test = (fn, ...args) => {
21
+ try {
22
+ return !!fn(...args);
23
+ } catch (e) {
24
+ return false
25
+ }
26
+ }
27
+
28
+ const supportsRequestStream = isReadableStreamSupported && test(() => {
29
+ let duplexAccessed = false;
30
+
31
+ const hasContentType = new Request(platform.origin, {
32
+ body: new ReadableStream(),
33
+ method: 'POST',
34
+ get duplex() {
35
+ duplexAccessed = true;
36
+ return 'half';
37
+ },
38
+ }).headers.has('Content-Type');
39
+
40
+ return duplexAccessed && !hasContentType;
41
+ });
42
+
43
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
44
+
45
+ const supportsResponseStream = isReadableStreamSupported &&
46
+ test(() => utils.isReadableStream(new Response('').body));
47
+
48
+
49
+ const resolvers = {
50
+ stream: supportsResponseStream && ((res) => res.body)
51
+ };
52
+
53
+ isFetchSupported && (((res) => {
54
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
55
+ !resolvers[type] && (resolvers[type] = utils.isFunction(res[type]) ? (res) => res[type]() :
56
+ (_, config) => {
57
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
58
+ })
59
+ });
60
+ })(new Response));
61
+
62
+ const getBodyLength = async (body) => {
63
+ if (body == null) {
64
+ return 0;
65
+ }
66
+
67
+ if(utils.isBlob(body)) {
68
+ return body.size;
69
+ }
70
+
71
+ if(utils.isSpecCompliantForm(body)) {
72
+ return (await new Request(body).arrayBuffer()).byteLength;
73
+ }
74
+
75
+ if(utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
76
+ return body.byteLength;
77
+ }
78
+
79
+ if(utils.isURLSearchParams(body)) {
80
+ body = body + '';
81
+ }
82
+
83
+ if(utils.isString(body)) {
84
+ return (await encodeText(body)).byteLength;
85
+ }
86
+ }
87
+
88
+ const resolveBodyLength = async (headers, body) => {
89
+ const length = utils.toFiniteNumber(headers.getContentLength());
90
+
91
+ return length == null ? getBodyLength(body) : length;
92
+ }
93
+
94
+ export default isFetchSupported && (async (config) => {
95
+ let {
96
+ url,
97
+ method,
98
+ data,
99
+ signal,
100
+ cancelToken,
101
+ timeout,
102
+ onDownloadProgress,
103
+ onUploadProgress,
104
+ responseType,
105
+ headers,
106
+ withCredentials = 'same-origin',
107
+ fetchOptions
108
+ } = resolveConfig(config);
109
+
110
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
111
+
112
+ let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
113
+ composeSignals([signal, cancelToken], timeout) : [];
114
+
115
+ let finished, request;
116
+
117
+ const onFinish = () => {
118
+ !finished && setTimeout(() => {
119
+ composedSignal && composedSignal.unsubscribe();
120
+ });
121
+
122
+ finished = true;
123
+ }
124
+
125
+ let requestContentLength;
126
+
127
+ try {
128
+ if (
129
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
130
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
131
+ ) {
132
+ let _request = new Request(url, {
133
+ method: 'POST',
134
+ body: data,
135
+ duplex: "half"
136
+ });
137
+
138
+ let contentTypeHeader;
139
+
140
+ if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
141
+ headers.setContentType(contentTypeHeader)
142
+ }
143
+
144
+ if (_request.body) {
145
+ const [onProgress, flush] = progressEventDecorator(
146
+ requestContentLength,
147
+ progressEventReducer(asyncDecorator(onUploadProgress))
148
+ );
149
+
150
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
151
+ }
152
+ }
153
+
154
+ if (!utils.isString(withCredentials)) {
155
+ withCredentials = withCredentials ? 'include' : 'omit';
156
+ }
157
+
158
+ request = new Request(url, {
159
+ ...fetchOptions,
160
+ signal: composedSignal,
161
+ method: method.toUpperCase(),
162
+ headers: headers.normalize().toJSON(),
163
+ body: data,
164
+ duplex: "half",
165
+ credentials: withCredentials
166
+ });
167
+
168
+ let response = await fetch(request);
169
+
170
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
171
+
172
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
173
+ const options = {};
174
+
175
+ ['status', 'statusText', 'headers'].forEach(prop => {
176
+ options[prop] = response[prop];
177
+ });
178
+
179
+ const responseContentLength = utils.toFiniteNumber(response.headers.get('content-length'));
180
+
181
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
182
+ responseContentLength,
183
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
184
+ ) || [];
185
+
186
+ response = new Response(
187
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
188
+ flush && flush();
189
+ isStreamResponse && onFinish();
190
+ }, encodeText),
191
+ options
192
+ );
193
+ }
194
+
195
+ responseType = responseType || 'text';
196
+
197
+ let responseData = await resolvers[utils.findKey(resolvers, responseType) || 'text'](response, config);
198
+
199
+ !isStreamResponse && onFinish();
200
+
201
+ stopTimeout && stopTimeout();
202
+
203
+ return await new Promise((resolve, reject) => {
204
+ settle(resolve, reject, {
205
+ data: responseData,
206
+ headers: AxiosHeaders.from(response.headers),
207
+ status: response.status,
208
+ statusText: response.statusText,
209
+ config,
210
+ request
211
+ })
212
+ })
213
+ } catch (err) {
214
+ onFinish();
215
+
216
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
217
+ throw Object.assign(
218
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
219
+ {
220
+ cause: err.cause || err
221
+ }
222
+ )
223
+ }
224
+
225
+ throw AxiosError.from(err, err && err.code, config, request);
226
+ }
227
+ });
228
+
229
+
@@ -19,11 +19,12 @@ import fromDataURI from '../helpers/fromDataURI.js';
19
19
  import stream from 'stream';
20
20
  import AxiosHeaders from '../core/AxiosHeaders.js';
21
21
  import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
22
- import EventEmitter from 'events';
22
+ import {EventEmitter} from 'events';
23
23
  import formDataToStream from "../helpers/formDataToStream.js";
24
24
  import readBlob from "../helpers/readBlob.js";
25
25
  import ZlibHeaderTransformStream from '../helpers/ZlibHeaderTransformStream.js';
26
26
  import callbackify from "../helpers/callbackify.js";
27
+ import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
27
28
 
28
29
  const zlibOptions = {
29
30
  flush: zlib.constants.Z_SYNC_FLUSH,
@@ -45,6 +46,14 @@ const supportedProtocols = platform.protocols.map(protocol => {
45
46
  return protocol + ':';
46
47
  });
47
48
 
49
+ const flushOnFinish = (stream, [throttled, flush]) => {
50
+ stream
51
+ .on('end', flush)
52
+ .on('error', flush);
53
+
54
+ return throttled;
55
+ }
56
+
48
57
  /**
49
58
  * If the proxy or config beforeRedirects functions are defined, call them with the options
50
59
  * object.
@@ -278,8 +287,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
278
287
  // Only set header if it hasn't been set in config
279
288
  headers.set('User-Agent', 'axios/' + VERSION, false);
280
289
 
281
- const onDownloadProgress = config.onDownloadProgress;
282
- const onUploadProgress = config.onUploadProgress;
290
+ const {onUploadProgress, onDownloadProgress} = config;
283
291
  const maxRate = config.maxRate;
284
292
  let maxUploadRate = undefined;
285
293
  let maxDownloadRate = undefined;
@@ -352,15 +360,16 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
352
360
  }
353
361
 
354
362
  data = stream.pipeline([data, new AxiosTransformStream({
355
- length: contentLength,
356
363
  maxRate: utils.toFiniteNumber(maxUploadRate)
357
364
  })], utils.noop);
358
365
 
359
- onUploadProgress && data.on('progress', progress => {
360
- onUploadProgress(Object.assign(progress, {
361
- upload: true
362
- }));
363
- });
366
+ onUploadProgress && data.on('progress', flushOnFinish(
367
+ data,
368
+ progressEventDecorator(
369
+ contentLength,
370
+ progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
371
+ )
372
+ ));
364
373
  }
365
374
 
366
375
  // HTTP basic authentication
@@ -459,17 +468,18 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
459
468
 
460
469
  const responseLength = +res.headers['content-length'];
461
470
 
462
- if (onDownloadProgress) {
471
+ if (onDownloadProgress || maxDownloadRate) {
463
472
  const transformStream = new AxiosTransformStream({
464
- length: utils.toFiniteNumber(responseLength),
465
473
  maxRate: utils.toFiniteNumber(maxDownloadRate)
466
474
  });
467
475
 
468
- onDownloadProgress && transformStream.on('progress', progress => {
469
- onDownloadProgress(Object.assign(progress, {
470
- download: true
471
- }));
472
- });
476
+ onDownloadProgress && transformStream.on('progress', flushOnFinish(
477
+ transformStream,
478
+ progressEventDecorator(
479
+ responseLength,
480
+ progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
481
+ )
482
+ ));
473
483
 
474
484
  streams.push(transformStream);
475
485
  }
@@ -1,93 +1,41 @@
1
- 'use strict';
2
-
3
1
  import utils from './../utils.js';
4
2
  import settle from './../core/settle.js';
5
- import cookies from './../helpers/cookies.js';
6
- import buildURL from './../helpers/buildURL.js';
7
- import buildFullPath from '../core/buildFullPath.js';
8
- import isURLSameOrigin from './../helpers/isURLSameOrigin.js';
9
3
  import transitionalDefaults from '../defaults/transitional.js';
10
4
  import AxiosError from '../core/AxiosError.js';
11
5
  import CanceledError from '../cancel/CanceledError.js';
12
6
  import parseProtocol from '../helpers/parseProtocol.js';
13
7
  import platform from '../platform/index.js';
14
8
  import AxiosHeaders from '../core/AxiosHeaders.js';
15
- import speedometer from '../helpers/speedometer.js';
16
-
17
- function progressEventReducer(listener, isDownloadStream) {
18
- let bytesNotified = 0;
19
- const _speedometer = speedometer(50, 250);
20
-
21
- return e => {
22
- const loaded = e.loaded;
23
- const total = e.lengthComputable ? e.total : undefined;
24
- const progressBytes = loaded - bytesNotified;
25
- const rate = _speedometer(progressBytes);
26
- const inRange = loaded <= total;
27
-
28
- bytesNotified = loaded;
29
-
30
- const data = {
31
- loaded,
32
- total,
33
- progress: total ? (loaded / total) : undefined,
34
- bytes: progressBytes,
35
- rate: rate ? rate : undefined,
36
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
37
- event: e
38
- };
39
-
40
- data[isDownloadStream ? 'download' : 'upload'] = true;
41
-
42
- listener(data);
43
- };
44
- }
9
+ import {progressEventReducer} from '../helpers/progressEventReducer.js';
10
+ import resolveConfig from "../helpers/resolveConfig.js";
45
11
 
46
12
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
47
13
 
48
14
  export default isXHRAdapterSupported && function (config) {
49
15
  return new Promise(function dispatchXhrRequest(resolve, reject) {
50
- let requestData = config.data;
51
- const requestHeaders = AxiosHeaders.from(config.headers).normalize();
52
- let {responseType, withXSRFToken} = config;
16
+ const _config = resolveConfig(config);
17
+ let requestData = _config.data;
18
+ const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
19
+ let {responseType, onUploadProgress, onDownloadProgress} = _config;
53
20
  let onCanceled;
54
- function done() {
55
- if (config.cancelToken) {
56
- config.cancelToken.unsubscribe(onCanceled);
57
- }
21
+ let uploadThrottled, downloadThrottled;
22
+ let flushUpload, flushDownload;
58
23
 
59
- if (config.signal) {
60
- config.signal.removeEventListener('abort', onCanceled);
61
- }
62
- }
24
+ function done() {
25
+ flushUpload && flushUpload(); // flush events
26
+ flushDownload && flushDownload(); // flush events
63
27
 
64
- let contentType;
28
+ _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
65
29
 
66
- if (utils.isFormData(requestData)) {
67
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
68
- requestHeaders.setContentType(false); // Let the browser set it
69
- } else if ((contentType = requestHeaders.getContentType()) !== false) {
70
- // fix semicolon duplication issue for ReactNative FormData implementation
71
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
72
- requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
73
- }
30
+ _config.signal && _config.signal.removeEventListener('abort', onCanceled);
74
31
  }
75
32
 
76
33
  let request = new XMLHttpRequest();
77
34
 
78
- // HTTP basic authentication
79
- if (config.auth) {
80
- const username = config.auth.username || '';
81
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
82
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
83
- }
84
-
85
- const fullPath = buildFullPath(config.baseURL, config.url);
86
-
87
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
35
+ request.open(_config.method.toUpperCase(), _config.url, true);
88
36
 
89
37
  // Set the request timeout in MS
90
- request.timeout = config.timeout;
38
+ request.timeout = _config.timeout;
91
39
 
92
40
  function onloadend() {
93
41
  if (!request) {
@@ -167,10 +115,10 @@ export default isXHRAdapterSupported && function (config) {
167
115
 
168
116
  // Handle timeout
169
117
  request.ontimeout = function handleTimeout() {
170
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
171
- const transitional = config.transitional || transitionalDefaults;
172
- if (config.timeoutErrorMessage) {
173
- timeoutErrorMessage = config.timeoutErrorMessage;
118
+ let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
119
+ const transitional = _config.transitional || transitionalDefaults;
120
+ if (_config.timeoutErrorMessage) {
121
+ timeoutErrorMessage = _config.timeoutErrorMessage;
174
122
  }
175
123
  reject(new AxiosError(
176
124
  timeoutErrorMessage,
@@ -182,22 +130,6 @@ export default isXHRAdapterSupported && function (config) {
182
130
  request = null;
183
131
  };
184
132
 
185
- // Add xsrf header
186
- // This is only done if running in a standard browser environment.
187
- // Specifically not if we're in a web worker, or react-native.
188
- if(platform.hasStandardBrowserEnv) {
189
- withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
190
-
191
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
192
- // Add xsrf header
193
- const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
194
-
195
- if (xsrfValue) {
196
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
197
- }
198
- }
199
- }
200
-
201
133
  // Remove Content-Type if data is undefined
202
134
  requestData === undefined && requestHeaders.setContentType(null);
203
135
 
@@ -209,26 +141,31 @@ export default isXHRAdapterSupported && function (config) {
209
141
  }
210
142
 
211
143
  // Add withCredentials to request if needed
212
- if (!utils.isUndefined(config.withCredentials)) {
213
- request.withCredentials = !!config.withCredentials;
144
+ if (!utils.isUndefined(_config.withCredentials)) {
145
+ request.withCredentials = !!_config.withCredentials;
214
146
  }
215
147
 
216
148
  // Add responseType to request if needed
217
149
  if (responseType && responseType !== 'json') {
218
- request.responseType = config.responseType;
150
+ request.responseType = _config.responseType;
219
151
  }
220
152
 
221
153
  // Handle progress if needed
222
- if (typeof config.onDownloadProgress === 'function') {
223
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
154
+ if (onDownloadProgress) {
155
+ ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
156
+ request.addEventListener('progress', downloadThrottled);
224
157
  }
225
158
 
226
159
  // Not all browsers support upload events
227
- if (typeof config.onUploadProgress === 'function' && request.upload) {
228
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
160
+ if (onUploadProgress && request.upload) {
161
+ ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
162
+
163
+ request.upload.addEventListener('progress', uploadThrottled);
164
+
165
+ request.upload.addEventListener('loadend', flushUpload);
229
166
  }
230
167
 
231
- if (config.cancelToken || config.signal) {
168
+ if (_config.cancelToken || _config.signal) {
232
169
  // Handle cancellation
233
170
  // eslint-disable-next-line func-names
234
171
  onCanceled = cancel => {
@@ -240,13 +177,13 @@ export default isXHRAdapterSupported && function (config) {
240
177
  request = null;
241
178
  };
242
179
 
243
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
244
- if (config.signal) {
245
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
180
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
181
+ if (_config.signal) {
182
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
246
183
  }
247
184
  }
248
185
 
249
- const protocol = parseProtocol(fullPath);
186
+ const protocol = parseProtocol(_config.url);
250
187
 
251
188
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
252
189
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
package/lib/core/Axios.js CHANGED
@@ -46,12 +46,15 @@ class Axios {
46
46
 
47
47
  // slice off the Error: ... line
48
48
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
49
-
50
- if (!err.stack) {
51
- err.stack = stack;
52
- // match without the 2 top stack lines
53
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
54
- err.stack += '\n' + stack
49
+ try {
50
+ if (!err.stack) {
51
+ err.stack = stack;
52
+ // match without the 2 top stack lines
53
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
54
+ err.stack += '\n' + stack
55
+ }
56
+ } catch (e) {
57
+ // ignore the case where "stack" is an un-writable property
55
58
  }
56
59
  }
57
60
 
@@ -100,6 +100,10 @@ class AxiosHeaders {
100
100
  setHeaders(header, valueOrRewrite)
101
101
  } else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
102
102
  setHeaders(parseHeaders(header), valueOrRewrite);
103
+ } else if (utils.isHeaders(header)) {
104
+ for (const [key, value] of header.entries()) {
105
+ setHeader(value, key, rewrite);
106
+ }
103
107
  } else {
104
108
  header != null && setHeader(valueOrRewrite, header, rewrite);
105
109
  }
@@ -3,7 +3,7 @@
3
3
  import utils from '../utils.js';
4
4
  import AxiosHeaders from "./AxiosHeaders.js";
5
5
 
6
- const headersToObject = (thing) => thing instanceof AxiosHeaders ? thing.toJSON() : thing;
6
+ const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
7
7
 
8
8
  /**
9
9
  * Config-specific merge-function which creates a new config-object
@@ -37,7 +37,7 @@ const defaults = {
37
37
 
38
38
  transitional: transitionalDefaults,
39
39
 
40
- adapter: ['xhr', 'http'],
40
+ adapter: ['xhr', 'http', 'fetch'],
41
41
 
42
42
  transformRequest: [function transformRequest(data, headers) {
43
43
  const contentType = headers.getContentType() || '';
@@ -58,7 +58,8 @@ const defaults = {
58
58
  utils.isBuffer(data) ||
59
59
  utils.isStream(data) ||
60
60
  utils.isFile(data) ||
61
- utils.isBlob(data)
61
+ utils.isBlob(data) ||
62
+ utils.isReadableStream(data)
62
63
  ) {
63
64
  return data;
64
65
  }
@@ -101,6 +102,10 @@ const defaults = {
101
102
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
102
103
  const JSONRequested = this.responseType === 'json';
103
104
 
105
+ if (utils.isResponse(data) || utils.isReadableStream(data)) {
106
+ return data;
107
+ }
108
+
104
109
  if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
105
110
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
106
111
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.6.7";
1
+ export const VERSION = "1.7.3";