mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Merge branch 'cookieMr-master'
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
[](http://npm-stat.com/charts.html?package=axios)
|
[](http://npm-stat.com/charts.html?package=axios)
|
||||||
[](https://gitter.im/mzabriskie/axios)
|
[](https://gitter.im/mzabriskie/axios)
|
||||||
[](https://www.codetriage.com/axios/axios)
|
[](https://www.codetriage.com/axios/axios)
|
||||||
|
[](https://snyk.io/test/npm/axios)
|
||||||
|
|
||||||
Promise based HTTP client for the browser and node.js
|
Promise based HTTP client for the browser and node.js
|
||||||
|
|
||||||
|
|||||||
Vendored
+3
@@ -107,6 +107,9 @@ export interface AxiosRequestConfig<D = any> {
|
|||||||
transitional?: TransitionalOptions;
|
transitional?: TransitionalOptions;
|
||||||
signal?: AbortSignal;
|
signal?: AbortSignal;
|
||||||
insecureHTTPParser?: boolean;
|
insecureHTTPParser?: boolean;
|
||||||
|
env?: {
|
||||||
|
FormData?: new (...args: any[]) => object;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HeadersDefaults {
|
export interface HeadersDefaults {
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ module.exports = function httpAdapter(config) {
|
|||||||
headers['User-Agent'] = 'axios/' + VERSION;
|
headers['User-Agent'] = 'axios/' + VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data && !utils.isStream(data)) {
|
if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
|
||||||
|
Object.assign(headers, data.getHeaders());
|
||||||
|
} else if (data && !utils.isStream(data)) {
|
||||||
if (Buffer.isBuffer(data)) {
|
if (Buffer.isBuffer(data)) {
|
||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
} else if (utils.isArrayBuffer(data)) {
|
} else if (utils.isArrayBuffer(data)) {
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|||||||
config = configOrUrl || {};
|
config = configOrUrl || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.url) {
|
|
||||||
throw new Error('Provided config url is not valid');
|
|
||||||
}
|
|
||||||
|
|
||||||
config = mergeConfig(this.defaults, config);
|
config = mergeConfig(this.defaults, config);
|
||||||
|
|
||||||
// Set config.method
|
// Set config.method
|
||||||
@@ -122,9 +118,6 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Axios.prototype.getUri = function getUri(config) {
|
Axios.prototype.getUri = function getUri(config) {
|
||||||
if (!config.url) {
|
|
||||||
throw new Error('Provided config url is not valid');
|
|
||||||
}
|
|
||||||
config = mergeConfig(this.defaults, config);
|
config = mergeConfig(this.defaults, config);
|
||||||
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-1
@@ -3,6 +3,7 @@
|
|||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var normalizeHeaderName = require('./helpers/normalizeHeaderName');
|
var normalizeHeaderName = require('./helpers/normalizeHeaderName');
|
||||||
var enhanceError = require('./core/enhanceError');
|
var enhanceError = require('./core/enhanceError');
|
||||||
|
var toFormData = require('./helpers/toFormData');
|
||||||
|
|
||||||
var DEFAULT_CONTENT_TYPE = {
|
var DEFAULT_CONTENT_TYPE = {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
@@ -71,10 +72,17 @@ var defaults = {
|
|||||||
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
||||||
return data.toString();
|
return data.toString();
|
||||||
}
|
}
|
||||||
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
|
||||||
|
var isObjectPayload = utils.isObject(data);
|
||||||
|
var contentType = headers && headers['Content-Type'];
|
||||||
|
|
||||||
|
if ( isObjectPayload && contentType === 'multipart/form-data' ) {
|
||||||
|
return toFormData(data, new (this.env && this.env.FormData || FormData));
|
||||||
|
} else if ( isObjectPayload || contentType === 'application/json' ) {
|
||||||
setContentTypeIfUnset(headers, 'application/json');
|
setContentTypeIfUnset(headers, 'application/json');
|
||||||
return stringifySafely(data);
|
return stringifySafely(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@@ -112,6 +120,8 @@ var defaults = {
|
|||||||
maxContentLength: -1,
|
maxContentLength: -1,
|
||||||
maxBodyLength: -1,
|
maxBodyLength: -1,
|
||||||
|
|
||||||
|
env: {},
|
||||||
|
|
||||||
validateStatus: function validateStatus(status) {
|
validateStatus: function validateStatus(status) {
|
||||||
return status >= 200 && status < 300;
|
return status >= 200 && status < 300;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var utils = require('../utils');
|
||||||
|
|
||||||
function combinedKey(parentKey, elKey) {
|
function combinedKey(parentKey, elKey) {
|
||||||
return parentKey + '.' + elKey;
|
return parentKey + '.' + elKey;
|
||||||
}
|
}
|
||||||
@@ -11,7 +13,7 @@ function buildFormData(formData, data, parentKey) {
|
|||||||
});
|
});
|
||||||
} else if (
|
} else if (
|
||||||
typeof data === 'object' &&
|
typeof data === 'object' &&
|
||||||
!(data instanceof File || data === null)
|
!(utils.isFile(data) || data === null)
|
||||||
) {
|
) {
|
||||||
Object.keys(data).forEach(function buildObject(key) {
|
Object.keys(data).forEach(function buildObject(key) {
|
||||||
buildFormData(
|
buildFormData(
|
||||||
@@ -44,10 +46,12 @@ function buildFormData(formData, data, parentKey) {
|
|||||||
* type FormVal = FormDataNest | FormDataPrimitive
|
* type FormVal = FormDataNest | FormDataPrimitive
|
||||||
*
|
*
|
||||||
* @param {FormVal} data
|
* @param {FormVal} data
|
||||||
|
* @param {?Object} formData
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function getFormData(data) {
|
module.exports = function getFormData(data, formData) {
|
||||||
var formData = new FormData();
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
formData = formData || new FormData();
|
||||||
|
|
||||||
buildFormData(formData, data);
|
buildFormData(formData, data);
|
||||||
|
|
||||||
|
|||||||
+15
-9
@@ -47,15 +47,6 @@ function isArrayBuffer(val) {
|
|||||||
return toString.call(val) === '[object ArrayBuffer]';
|
return toString.call(val) === '[object ArrayBuffer]';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a value is a FormData
|
|
||||||
*
|
|
||||||
* @param {Object} val The value to test
|
|
||||||
* @returns {boolean} True if value is an FormData, otherwise false
|
|
||||||
*/
|
|
||||||
function isFormData(val) {
|
|
||||||
return toString.call(val) === '[object FormData]';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a value is a view on an ArrayBuffer
|
* Determine if a value is a view on an ArrayBuffer
|
||||||
@@ -168,6 +159,21 @@ function isStream(val) {
|
|||||||
return isObject(val) && isFunction(val.pipe);
|
return isObject(val) && isFunction(val.pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is a FormData
|
||||||
|
*
|
||||||
|
* @param {Object} thing The value to test
|
||||||
|
* @returns {boolean} True if value is an FormData, otherwise false
|
||||||
|
*/
|
||||||
|
function isFormData(thing) {
|
||||||
|
var pattern = '[object FormData]';
|
||||||
|
return thing && (
|
||||||
|
(typeof FormData === 'function' && thing instanceof FormData) ||
|
||||||
|
toString.call(thing) === pattern ||
|
||||||
|
(isFunction(thing.toString) && thing.toString() === pattern)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a value is a URLSearchParams object
|
* Determine if a value is a URLSearchParams object
|
||||||
*
|
*
|
||||||
|
|||||||
Generated
+9
-9
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "axios",
|
"name": "axios",
|
||||||
"version": "0.24.0",
|
"version": "0.25.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"version": "0.24.0",
|
"version": "0.25.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.14.7"
|
"follow-redirects": "^1.14.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"abortcontroller-polyfill": "^1.5.0",
|
"abortcontroller-polyfill": "^1.5.0",
|
||||||
@@ -5603,9 +5603,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/follow-redirects": {
|
"node_modules/follow-redirects": {
|
||||||
"version": "1.14.7",
|
"version": "1.14.8",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
|
||||||
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
|
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "individual",
|
"type": "individual",
|
||||||
@@ -20841,9 +20841,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"follow-redirects": {
|
"follow-redirects": {
|
||||||
"version": "1.14.7",
|
"version": "1.14.8",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
|
||||||
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ=="
|
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA=="
|
||||||
},
|
},
|
||||||
"for-in": {
|
"for-in": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@
|
|||||||
"unpkg": "dist/axios.min.js",
|
"unpkg": "dist/axios.min.js",
|
||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.14.7"
|
"follow-redirects": "^1.14.8"
|
||||||
},
|
},
|
||||||
"bundlesize": [
|
"bundlesize": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var toFormData = require("../../../lib/helpers/toFormData");
|
var toFormData = require("../../../lib/helpers/toFormData");
|
||||||
|
|
||||||
describe("toFormData", function () {
|
describe("toFormData", function () {
|
||||||
it("Convert nested data object to FormDAta", function () {
|
it("Convert nested data object to FormData", function () {
|
||||||
var o = {
|
var o = {
|
||||||
val: 123,
|
val: 123,
|
||||||
nested: {
|
nested: {
|
||||||
|
|||||||
@@ -7,24 +7,6 @@ describe('requests', function () {
|
|||||||
jasmine.Ajax.uninstall();
|
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) {
|
it('should treat single string arg as url', function (done) {
|
||||||
axios('/foo');
|
axios('/foo');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user