mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Release/v0.22.0 (#4107)
* fix/Avoid package.json import; (#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <jasonsaayman@gmail.com> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <jasonsaayman@gmail.com> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
+29
-7
@@ -10,9 +10,11 @@ var httpFollow = require('follow-redirects').http;
|
||||
var httpsFollow = require('follow-redirects').https;
|
||||
var url = require('url');
|
||||
var zlib = require('zlib');
|
||||
var pkg = require('./../../package.json');
|
||||
var VERSION = require('./../env/data').version;
|
||||
var createError = require('../core/createError');
|
||||
var enhanceError = require('../core/enhanceError');
|
||||
var defaults = require('../defaults');
|
||||
var Cancel = require('../cancel/Cancel');
|
||||
|
||||
var isHttps = /https:?/;
|
||||
|
||||
@@ -44,10 +46,22 @@ function setProxy(options, proxy, location) {
|
||||
/*eslint consistent-return:0*/
|
||||
module.exports = function httpAdapter(config) {
|
||||
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
||||
var onCanceled;
|
||||
function done() {
|
||||
if (config.cancelToken) {
|
||||
config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
|
||||
if (config.signal) {
|
||||
config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
var resolve = function resolve(value) {
|
||||
done();
|
||||
resolvePromise(value);
|
||||
};
|
||||
var reject = function reject(value) {
|
||||
done();
|
||||
rejectPromise(value);
|
||||
};
|
||||
var data = config.data;
|
||||
@@ -68,7 +82,7 @@ module.exports = function httpAdapter(config) {
|
||||
// Otherwise, use specified value
|
||||
} else {
|
||||
// Only set header if it hasn't been set in config
|
||||
headers['User-Agent'] = 'axios/' + pkg.version;
|
||||
headers['User-Agent'] = 'axios/' + VERSION;
|
||||
}
|
||||
|
||||
if (data && !utils.isStream(data)) {
|
||||
@@ -310,25 +324,33 @@ module.exports = function httpAdapter(config) {
|
||||
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
||||
req.setTimeout(timeout, function handleRequestTimeout() {
|
||||
req.abort();
|
||||
var transitional = config.transitional || defaults.transitional;
|
||||
reject(createError(
|
||||
'timeout of ' + timeout + 'ms exceeded',
|
||||
config,
|
||||
config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
||||
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
||||
req
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
if (config.cancelToken) {
|
||||
if (config.cancelToken || config.signal) {
|
||||
// Handle cancellation
|
||||
config.cancelToken.promise.then(function onCanceled(cancel) {
|
||||
// eslint-disable-next-line func-names
|
||||
onCanceled = function(cancel) {
|
||||
if (req.aborted) return;
|
||||
|
||||
req.abort();
|
||||
reject(cancel);
|
||||
});
|
||||
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
|
||||
};
|
||||
|
||||
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
||||
if (config.signal) {
|
||||
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send the request
|
||||
if (utils.isStream(data)) {
|
||||
data.on('error', function handleStreamError(err) {
|
||||
|
||||
Reference in New Issue
Block a user