2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-30 15:24:11 +03:00

Merge pull request #1 from axios/master

Sync fork with axios/axios
This commit is contained in:
Ben Carp
2022-01-23 21:23:22 +02:00
committed by GitHub
17 changed files with 29530 additions and 38 deletions
-2
View File
@@ -7,5 +7,3 @@ typings/
coverage/
test/typescript/axios.js*
sauce_connect.log
package-lock.json
yarn.lock
+55
View File
@@ -1,5 +1,60 @@
# Changelog
### 0.25.0 (January 18, 2022)
Breaking changes:
- Fixing maxBodyLength enforcement ([#3786](https://github.com/axios/axios/pull/3786))
- Don't rely on strict mode behaviour for arguments ([#3470](https://github.com/axios/axios/pull/3470))
- Adding error handling when missing url ([#3791](https://github.com/axios/axios/pull/3791))
- Update isAbsoluteURL.js removing escaping of non-special characters ([#3809](https://github.com/axios/axios/pull/3809))
- Use native Array.isArray() in utils.js ([#3836](https://github.com/axios/axios/pull/3836))
- Adding error handling inside stream end callback ([#3967](https://github.com/axios/axios/pull/3967))
Fixes and Functionality:
- Added aborted even handler ([#3916](https://github.com/axios/axios/pull/3916))
- Header types expanded allowing `boolean` and `number` types ([#4144](https://github.com/axios/axios/pull/4144))
- Fix cancel signature allowing cancel message to be `undefined` ([#3153](https://github.com/axios/axios/pull/3153))
- Updated type checks to be formulated better ([#3342](https://github.com/axios/axios/pull/3342))
- Avoid unnecessary buffer allocations ([#3321](https://github.com/axios/axios/pull/3321))
- Adding a socket handler to keep TCP connection live when processing long living requests ([#3422](https://github.com/axios/axios/pull/3422))
- Added toFormData helper function ([#3757](https://github.com/axios/axios/pull/3757))
- Adding responseEncoding prop type in AxiosRequestConfig ([#3918](https://github.com/axios/axios/pull/3918))
Internal and Tests:
- Adding axios-test-instance to ecosystem ([#3786](https://github.com/axios/axios/pull/3786))
- Optimize the logic of isAxiosError ([#3546](https://github.com/axios/axios/pull/3546))
- Add tests and documentation to display how multiple inceptors work ([#3564](https://github.com/axios/axios/pull/3564))
- Updating follow-redirects to version 1.14.7 ([#4379](https://github.com/axios/axios/pull/4379))
Documentation:
- Fixing changelog to show corrext pull request ([#4219](https://github.com/axios/axios/pull/4219))
- Update upgrade guide for https proxy setting ([#3604](https://github.com/axios/axios/pull/3604))
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
- [Jay](mailto:jasonsaayman@gmail.com)
- [Rijk van Zanten](https://github.com/rijkvanzanten)
- [Kohta Ito](https://github.com/koh110)
- [Brandon Faulkner](https://github.com/bfaulk96)
- [Stefano Magni](https://github.com/NoriSte)
- [enofan](https://github.com/fanguangyi)
- [Andrey Pechkurov](https://github.com/puzpuzpuz)
- [Doowonee](https://github.com/doowonee)
- [Emil Broman](https://github.com/emilbroman-eqt)
- [Remco Haszing](https://github.com/remcohaszing)
- [Black-Hole](https://github.com/BlackHole1)
- [Wolfram Kriesing](https://github.com/wolframkriesing)
- [Andrew Ovens](https://github.com/repl-andrew-ovens)
- [Paulo Renato](https://github.com/PauloRSF)
- [Ben Carp](https://github.com/carpben)
- [Hirotaka Tagawa](https://github.com/wafuwafu13)
- [狼族小狈](https://github.com/lzxb)
- [C. Lewis](https://github.com/ctjlewis)
- [Felipe Carvalho](https://github.com/FCarvalhoVII)
- [Daniel](https://github.com/djs113)
- [Gustavo Sales](https://github.com/gussalesdev)
### 0.24.0 (October 25, 2021)
Breaking changes:
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "axios",
"main": "./dist/axios.js",
"version": "0.24.0",
"version": "0.25.0",
"homepage": "https://axios-http.com",
"authors": [
"Matt Zabriskie"
+2
View File
@@ -1,3 +1,5 @@
/* axios v0.25.0 | (c) 2022 by Matt Zabriskie */
/* axios v0.24.0 | (c) 2022 by Matt Zabriskie */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
+2
View File
File diff suppressed because one or more lines are too long
Vendored
+15
View File
@@ -53,6 +53,20 @@ export type ResponseType =
| 'text'
| 'stream';
export type responseEncoding =
| 'ascii' | 'ASCII'
| 'ansi' | 'ANSI'
| 'binary' | 'BINARY'
| 'base64' | 'BASE64'
| 'base64url' | 'BASE64URL'
| 'hex' | 'HEX'
| 'latin1' | 'LATIN1'
| 'ucs-2' | 'UCS-2'
| 'ucs2' | 'UCS2'
| 'utf-8' | 'UTF-8'
| 'utf8' | 'UTF8'
| 'utf16le' | 'UTF16LE';
export interface TransitionalOptions {
silentJSONParsing?: boolean;
forcedJSONParsing?: boolean;
@@ -75,6 +89,7 @@ export interface AxiosRequestConfig<D = any> {
adapter?: AxiosAdapter;
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
responseEncoding?: responseEncoding | string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
+27 -8
View File
@@ -138,6 +138,16 @@ module.exports = function httpAdapter(config) {
var isHttpsRequest = isHttps.test(protocol);
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
try {
buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, '');
} catch (err) {
var customErr = new Error(err.message);
customErr.config = config;
customErr.url = config.url;
customErr.exists = true;
reject(customErr);
}
var options = {
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method.toUpperCase(),
@@ -297,15 +307,18 @@ module.exports = function httpAdapter(config) {
});
stream.on('end', function handleStreamEnd() {
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') {
responseData = responseData.toString(config.responseEncoding);
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
responseData = utils.stripBOM(responseData);
try {
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') {
responseData = responseData.toString(config.responseEncoding);
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
responseData = utils.stripBOM(responseData);
}
}
response.data = responseData;
} catch (err) {
reject(enhanceError(err, config, err.code, response.request, response));
}
response.data = responseData;
settle(resolve, reject, response);
});
}
@@ -346,9 +359,15 @@ 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 timeoutErrorMessage = '';
if (config.timeoutErrorMessage) {
timeoutErrorMessage = config.timeoutErrorMessage;
} else {
timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
}
var transitional = config.transitional || defaults.transitional;
reject(createError(
'timeout of ' + timeout + 'ms exceeded',
timeoutErrorMessage,
config,
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
req
+7
View File
@@ -36,6 +36,10 @@ Axios.prototype.request = function request(configOrUrl, config) {
config = configOrUrl || {};
}
if (!config.url) {
throw new Error('Provided config url is not valid');
}
config = mergeConfig(this.defaults, config);
// Set config.method
@@ -118,6 +122,9 @@ Axios.prototype.request = function request(configOrUrl, config) {
};
Axios.prototype.getUri = function getUri(config) {
if (!config.url) {
throw new Error('Provided config url is not valid');
}
config = mergeConfig(this.defaults, config);
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
};
+1 -1
View File
@@ -1,3 +1,3 @@
module.exports = {
"version": "0.24.0"
"version": "0.25.0"
};
+1 -1
View File
@@ -10,5 +10,5 @@ module.exports = function isAbsoluteURL(url) {
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
// by any combination of letters, digits, plus, period, or hyphen.
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
};
+1 -1
View File
@@ -13,7 +13,7 @@ var toString = Object.prototype.toString;
* @returns {boolean} True if value is an Array, otherwise false
*/
function isArray(val) {
return toString.call(val) === '[object Array]';
return Array.isArray(val);
}
/**
+29331
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "axios",
"version": "0.24.0",
"version": "0.25.0",
"description": "Promise based HTTP client for the browser and node.js",
"main": "index.js",
"types": "index.d.ts",
@@ -75,7 +75,7 @@
"unpkg": "dist/axios.min.js",
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "^1.14.4"
"follow-redirects": "^1.14.7"
},
"bundlesize": [
{
+1 -1
View File
@@ -11,7 +11,7 @@ describe('static api', function () {
});
it('should have promise method helpers', function () {
var promise = axios();
var promise = axios('/test');
expect(typeof promise.then).toEqual('function');
expect(typeof promise.catch).toEqual('function');
+21 -21
View File
@@ -67,28 +67,28 @@ describe('cancel', function() {
});
});
describe('when called after response has been received', function() {
// https://github.com/axios/axios/issues/482
it('does not cause unhandled rejection', function(done) {
var source = CancelToken.source();
axios.get('/foo', {
cancelToken: source.token
}).then(function() {
window.addEventListener('unhandledrejection', function() {
done.fail('Unhandled rejection.');
});
source.cancel();
setTimeout(done, 100);
});
// describe('when called after response has been received', function() {
// // https://github.com/axios/axios/issues/482
// it('does not cause unhandled rejection', function(done) {
// var source = CancelToken.source();
// axios.get('/foo', {
// cancelToken: source.token
// }).then(function() {
// window.addEventListener('unhandledrejection', function() {
// done.fail('Unhandled rejection.');
// });
// source.cancel();
// setTimeout(done, 100);
// });
getAjaxRequest().then(function(request) {
request.respondWith({
status: 200,
responseText: 'OK'
});
});
});
});
// getAjaxRequest().then(function(request) {
// request.respondWith({
// status: 200,
// responseText: 'OK'
// });
// });
// });
// });
it('it should support cancellation using AbortController signal', function(done) {
var controller = new AbortController();
+18
View File
@@ -7,6 +7,24 @@ describe('requests', function () {
jasmine.Ajax.uninstall();
});
it('should throw error when missing url', function (done) {
expect(() => axios()).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios('')).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios({
url: undefined,
})).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios({
method: 'POST',
})).toThrowError(/Provided config url is not valid/);
done();
});
it('should treat single string arg as url', function (done) {
axios('/foo');
+45
View File
@@ -116,6 +116,36 @@ describe('supports http with nodejs', function () {
});
});
it('should respect the timeoutErrorMessage property', function (done) {
server = http.createServer(function (req, res) {
setTimeout(function () {
res.end();
}, 1000);
}).listen(4444, function () {
var success = false, failure = false;
var error;
axios.get('http://localhost:4444/', {
timeout: 250,
timeoutErrorMessage: 'oops, timeout',
}).then(function (res) {
success = true;
}).catch(function (err) {
error = err;
failure = true;
});
setTimeout(function () {
assert.strictEqual(success, false, 'request should not succeed');
assert.strictEqual(failure, true, 'request should fail');
assert.strictEqual(error.code, 'ECONNABORTED');
assert.strictEqual(error.message, 'oops, timeout');
done();
}, 300);
});
});
it('should allow passing JSON', function (done) {
var data = {
firstName: 'Fred',
@@ -462,6 +492,21 @@ describe('supports http with nodejs', function () {
});
});
it('should display error while parsing params', function (done) {
server = http.createServer(function () {
}).listen(4444, function () {
axios.get('http://localhost:4444/', {
params: {
errorParam: new Date(undefined),
},
}).catch(function (err) {
assert.deepEqual(err.exists, true)
done();
});
});
});
it('should support sockets', function (done) {
// Different sockets for win32 vs darwin/linux
var socketName = './test.sock';