mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
This reverts commit 73e3bdb883.
This commit is contained in:
Vendored
-3
@@ -107,9 +107,6 @@ 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,9 +87,7 @@ module.exports = function httpAdapter(config) {
|
|||||||
headers['User-Agent'] = 'axios/' + VERSION;
|
headers['User-Agent'] = 'axios/' + VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
|
if (data && !utils.isStream(data)) {
|
||||||
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)) {
|
||||||
|
|||||||
+1
-11
@@ -3,7 +3,6 @@
|
|||||||
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'
|
||||||
@@ -72,17 +71,10 @@ 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;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@@ -120,8 +112,6 @@ 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,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var utils = require('../utils');
|
|
||||||
|
|
||||||
function combinedKey(parentKey, elKey) {
|
function combinedKey(parentKey, elKey) {
|
||||||
return parentKey + '.' + elKey;
|
return parentKey + '.' + elKey;
|
||||||
}
|
}
|
||||||
@@ -13,7 +11,7 @@ function buildFormData(formData, data, parentKey) {
|
|||||||
});
|
});
|
||||||
} else if (
|
} else if (
|
||||||
typeof data === 'object' &&
|
typeof data === 'object' &&
|
||||||
!(utils.isFile(data) || data === null)
|
!(data instanceof File || data === null)
|
||||||
) {
|
) {
|
||||||
Object.keys(data).forEach(function buildObject(key) {
|
Object.keys(data).forEach(function buildObject(key) {
|
||||||
buildFormData(
|
buildFormData(
|
||||||
@@ -46,12 +44,10 @@ 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, formData) {
|
module.exports = function getFormData(data) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
var formData = new FormData();
|
||||||
formData = formData || new FormData();
|
|
||||||
|
|
||||||
buildFormData(formData, data);
|
buildFormData(formData, data);
|
||||||
|
|
||||||
|
|||||||
+9
-15
@@ -47,6 +47,15 @@ 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
|
||||||
@@ -159,21 +168,6 @@ 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
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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: {
|
||||||
|
|||||||
Reference in New Issue
Block a user