From 747eb7da29f27235c6108aa4f9bf2f5b66c3e26f Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Sun, 26 Aug 2018 13:06:11 -0700 Subject: [PATCH 1/2] Add unit test for HTTP verb on redirect --- test/unit/adapters/http.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 8aca1cf8b3..f35c0e0707 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -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', From a27589d5f892bff898df0def49114afdb3421e87 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Sun, 26 Aug 2018 13:13:30 -0700 Subject: [PATCH 2/2] Uppercase HTTP verb before passing to follow-redirects --- lib/adapters/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 00dedc4c3f..d39a573a2a 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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