mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Fixing content-type header repeated (#4745)
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a11f9501b8
commit
1504792765
@@ -5,6 +5,7 @@ var transformData = require('./transformData');
|
||||
var isCancel = require('../cancel/isCancel');
|
||||
var defaults = require('../defaults');
|
||||
var CanceledError = require('../cancel/CanceledError');
|
||||
var normalizeHeaderName = require('../helpers/normalizeHeaderName');
|
||||
|
||||
/**
|
||||
* Throws a `CanceledError` if cancellation has been requested.
|
||||
@@ -40,6 +41,9 @@ module.exports = function dispatchRequest(config) {
|
||||
config.transformRequest
|
||||
);
|
||||
|
||||
normalizeHeaderName(config.headers, 'Accept');
|
||||
normalizeHeaderName(config.headers, 'Content-Type');
|
||||
|
||||
// Flatten headers
|
||||
config.headers = utils.merge(
|
||||
config.headers.common || {},
|
||||
|
||||
@@ -177,4 +177,24 @@ describe('transform', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should normalize \'content-type\' header when using a custom transformRequest', function (done) {
|
||||
var data = {
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
axios.post('/foo', data, {
|
||||
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
transformRequest: [
|
||||
function () {
|
||||
return 'aa=44'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
expect(request.requestHeaders['Content-Type']).toEqual('application/x-www-form-urlencoded');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user