mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -47,6 +47,13 @@ module.exports = function dispatchRequest(config) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Remove header where value is null
|
||||||
|
utils.forEach(config.headers, function deleteNullValueHeaders(value, key) {
|
||||||
|
if (value === null) {
|
||||||
|
delete config.headers[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var adapter = config.adapter || defaults.adapter;
|
var adapter = config.adapter || defaults.adapter;
|
||||||
|
|
||||||
return adapter(config).then(function onAdapterResolution(response) {
|
return adapter(config).then(function onAdapterResolution(response) {
|
||||||
|
|||||||
@@ -294,6 +294,11 @@ function deepMerge(/* obj1, obj2, obj3, ... */) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastArgument = arguments[arguments.length - 1];
|
||||||
|
if (lastArgument === null || typeof lastArgument === 'undefined') {
|
||||||
|
return lastArgument;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
forEach(arguments[i], assignValue);
|
forEach(arguments[i], assignValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,21 @@ describe('headers', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set header if value is null', function (done) {
|
||||||
|
expect(axios.defaults.headers.common['Accept']).toEqual('application/json, text/plain, */*');
|
||||||
|
|
||||||
|
axios('/foo', {
|
||||||
|
headers: {
|
||||||
|
Accept: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getAjaxRequest().then(function (request) {
|
||||||
|
expect(typeof request.requestHeaders['Accept']).toEqual('undefined');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should add extra headers for post', function (done) {
|
it('should add extra headers for post', function (done) {
|
||||||
var headers = axios.defaults.headers.common;
|
var headers = axios.defaults.headers.common;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('utils::deepMerge', function () {
|
|||||||
|
|
||||||
it('should deepMerge recursively', function () {
|
it('should deepMerge recursively', function () {
|
||||||
var a = {foo: {bar: 123}};
|
var a = {foo: {bar: 123}};
|
||||||
var b = {foo: {baz: 456}, bar: {qux: 789}};
|
var b = {foo: {baz: 456}, bar: {qux: null}};
|
||||||
|
|
||||||
expect(deepMerge(a, b)).toEqual({
|
expect(deepMerge(a, b)).toEqual({
|
||||||
foo: {
|
foo: {
|
||||||
@@ -34,7 +34,7 @@ describe('utils::deepMerge', function () {
|
|||||||
baz: 456
|
baz: 456
|
||||||
},
|
},
|
||||||
bar: {
|
bar: {
|
||||||
qux: 789
|
qux: null
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -54,13 +54,13 @@ describe('utils::deepMerge', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles null and undefined arguments', function () {
|
it('handles null and undefined arguments', function () {
|
||||||
expect(deepMerge(undefined, undefined)).toEqual({});
|
expect(deepMerge(undefined, undefined)).toEqual(undefined);
|
||||||
expect(deepMerge(undefined, {foo: 123})).toEqual({foo: 123});
|
expect(deepMerge(undefined, {foo: 123})).toEqual({foo: 123});
|
||||||
expect(deepMerge({foo: 123}, undefined)).toEqual({foo: 123});
|
expect(deepMerge({foo: 123}, undefined)).toEqual(undefined);
|
||||||
|
|
||||||
expect(deepMerge(null, null)).toEqual({});
|
expect(deepMerge(null, null)).toEqual(null);
|
||||||
expect(deepMerge(null, {foo: 123})).toEqual({foo: 123});
|
expect(deepMerge(null, {foo: 123})).toEqual({foo: 123});
|
||||||
expect(deepMerge({foo: 123}, null)).toEqual({foo: 123});
|
expect(deepMerge({foo: 123}, null)).toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user