Skip to content

Commit

Permalink
Preserve HTTP method when following redirect (#1758)
Browse files Browse the repository at this point in the history
Resolves #1158

This modifies http.js to uppercase the HTTP method, similar to xhr.js, before passing the request off to the transport. This causes follow-redirects to preserve the HTTP method when automatically making a request to the next URL.
  • Loading branch information
RikkiGibson authored and Khaledgarbaya committed Aug 27, 2018
1 parent 9005a54 commit 21ae22d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adapters/http.js
Expand Up @@ -83,7 +83,7 @@ module.exports = function httpAdapter(config) {

var options = {
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method,
method: config.method.toUpperCase(),
headers: headers,
agent: agent,
auth: auth
Expand Down
26 changes: 26 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -130,6 +130,32 @@ describe('supports http with nodejs', function () {
});
});

it('should preserve the HTTP verb on redirect', function (done) {
server = http.createServer(function (req, res) {
if (req.method.toLowerCase() !== "head") {
res.statusCode = 400;
res.end();
return;
}

var parsed = url.parse(req.url);
if (parsed.pathname === '/one') {
res.setHeader('Location', '/two');
res.statusCode = 302;
res.end();
} else {
res.end();
}
}).listen(4444, function () {
axios.head('http://localhost:4444/one').then(function (res) {
assert.equal(res.status, 200);
done();
}).catch(function (err) {
done(err);
});
});
});

it('should support transparent gunzip', function (done) {
var data = {
firstName: 'Fred',
Expand Down

0 comments on commit 21ae22d

Please sign in to comment.