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

Preserve HTTP method when following redirect #1758

Merged
merged 2 commits into from Aug 27, 2018
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
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