Comparing version 1.1.7 to 1.2.0
@@ -69,3 +69,3 @@ 'use strict'; | ||
utils.addEntry(axiosOptions, 'withCredentials', options.withCredentials); | ||
utils.addEntry(axiosOptions, 'headers', options.noXRequestedWithHeader ? options.headers : utils.assign({ 'X-Requested-With': 'XMLHttpRequest' }, options.headers)); | ||
utils.addEntry(axiosOptions, 'headers', options.noXRequestedWithHeader ? utils.lowerCaseHeaders(options.headers) : utils.lowerCaseHeaders(utils.assign({ 'x-requested-with': 'XMLHttpRequest' }, options.headers))); | ||
@@ -85,3 +85,3 @@ // 上传下载事件回调 | ||
utils.addEntry(axiosOptions, 'params', options.data); | ||
utils.addEntry(axiosOptions, 'headers.Content-Type', contentType); | ||
utils.addEntry(axiosOptions, 'headers.content-type', contentType); | ||
} | ||
@@ -91,6 +91,6 @@ | ||
utils.addEntry(axiosOptions, 'data', options.data); | ||
utils.addEntry(axiosOptions, 'headers.Content-Type', contentType || 'application/x-www-form-urlencoded; charset=UTF-8'); | ||
utils.addEntry(axiosOptions, 'headers.content-type', contentType || 'application/x-www-form-urlencoded; charset=UTF-8'); | ||
// Pass to server as is for other content types | ||
if (axiosOptions.headers['Content-Type'].toLowerCase().indexOf('application/x-www-form-urlencoded') !== -1) { | ||
if (axiosOptions.headers['content-type'].toLowerCase().indexOf('application/x-www-form-urlencoded') !== -1) { | ||
utils.addEntry(axiosOptions, 'transformRequest', utils.stringifyQueryString); | ||
@@ -101,3 +101,3 @@ } | ||
// JavaScript 因为 number 类型是浮点数,有些大整数以及高精度小数无法正确表示。 | ||
// @youzan/json-parse 可以将这些整数表示成字符串 | ||
// zan-json-parse 可以将这些整数表示成字符串 | ||
if (options.allowBigNumberInJSON) { | ||
@@ -104,0 +104,0 @@ utils.addEntry(axiosOptions, 'transformResponse', [function (data) { |
@@ -20,2 +20,3 @@ 'use strict'; | ||
exports.getHeaderContentType = getHeaderContentType; | ||
exports.lowerCaseHeaders = lowerCaseHeaders; | ||
@@ -152,3 +153,13 @@ var _qs = require('./qs'); | ||
function getHeaderContentType(contentType, headers) { | ||
function objectForEach(object, fn) { | ||
for (var key in object) { | ||
if (hasOwn.call(object, key)) { | ||
fn(object[key], key, object); | ||
} | ||
} | ||
} | ||
function getHeaderContentType(contentType) { | ||
var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (contentType) { | ||
@@ -158,10 +169,22 @@ return contentType; | ||
var headerKeys = Object.keys(headers || {}); | ||
var keyCount = headerKeys.length; | ||
for (var i = 1; i < keyCount; i++) { | ||
var key = headerKeys[i]; | ||
if (key.toLowerCase() === 'content-type') { | ||
return headers[key]; | ||
for (var key in headers) { | ||
if (hasOwn.call(headers, key)) { | ||
if (key.toLowerCase() === 'content-type') { | ||
return headers[key]; | ||
} | ||
} | ||
} | ||
} | ||
function lowerCaseHeaders(headers) { | ||
if (!headers) { | ||
return headers; | ||
} | ||
var newHeaders = {}; | ||
objectForEach(headers, function (val, key) { | ||
newHeaders[key.toLowerCase()] = val; | ||
}); | ||
return newHeaders; | ||
} |
{ | ||
"name": "zan-ajax", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"description": "Promise based HTTP client for the browser and node", | ||
@@ -37,10 +37,6 @@ "main": "lib/index.js", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-flowtype": "^2.34.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-lean-imports": "^0.3.3", | ||
"eslint-plugin-react": "^6.10.3", | ||
"jquery": "3.1.1" | ||
} | ||
} |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
28679
9
566
1