Skip to content

Commit

Permalink
Bug/allow header to contain http verb keys axios#1252 (axios#1258)
Browse files Browse the repository at this point in the history
* Failing test for axios#1252

* Only delete header keys that match an HTTP verb if the value is a non-string

Co-authored-by: David Ko <[email protected]>
Co-authored-by: Jay <[email protected]>
  • Loading branch information
3 people authored May 22, 2020
1 parent 1cdf9e4 commit 920510b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/core/dispatchRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module.exports = function dispatchRequest(config) {
utils.forEach(
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
function cleanHeaderConfig(method) {
delete config.headers[method];
if (typeof config.headers[method] !== 'string') {
delete config.headers[method];
}
}
);

Expand Down
13 changes: 13 additions & 0 deletions test/specs/headers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,17 @@ describe('headers', function () {
done();
});
});

describe('when a header key matches an HTTP verb', function() {
it('preserves the header value', function(done) {
axios.post('/foo', null, { 'headers': { 'delete': 'test' } });

getAjaxRequest().then(function (request) {
var headerValue = request.requestHeaders['delete'];

expect(headerValue).toEqual('test');
done();
});
});
});
});

0 comments on commit 920510b

Please sign in to comment.