Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing content-type header repeated #4745

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/core/dispatchRequest.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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 || {},
Expand Down
20 changes: 20 additions & 0 deletions test/specs/transform.spec.js
Expand Up @@ -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();
});
});
});