mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Fixing proxy beforeRedirect regression (#4708)
This commit is contained in:
@@ -204,7 +204,7 @@ describe('supports http with nodejs', function () {
|
||||
assert.equal(res.data, str);
|
||||
assert.equal(res.request.path, '/two');
|
||||
done();
|
||||
}).catch(done);;
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,7 +223,7 @@ describe('supports http with nodejs', function () {
|
||||
assert.equal(res.status, 302);
|
||||
assert.equal(res.headers['location'], '/foo');
|
||||
done();
|
||||
}).catch(done);;
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -241,7 +241,7 @@ describe('supports http with nodejs', function () {
|
||||
assert.equal(error.code, AxiosError.ERR_FR_TOO_MANY_REDIRECTS);
|
||||
assert.equal(error.message, 'Maximum number of redirects exceeded');
|
||||
done();
|
||||
});
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -263,6 +263,56 @@ describe('supports http with nodejs', function () {
|
||||
}).catch(function (error) {
|
||||
assert.equal(error.message, 'Provided path is not allowed');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support beforeRedirect and proxy with redirect', function (done) {
|
||||
var requestCount = 0;
|
||||
var totalRedirectCount = 5;
|
||||
server = http.createServer(function (req, res) {
|
||||
requestCount += 1;
|
||||
if (requestCount <= totalRedirectCount) {
|
||||
res.setHeader('Location', 'http://localhost:4444');
|
||||
res.writeHead(302);
|
||||
}
|
||||
res.end();
|
||||
}).listen(4444, function () {
|
||||
var proxyUseCount = 0;
|
||||
proxy = http.createServer(function (request, response) {
|
||||
proxyUseCount += 1;
|
||||
var parsed = url.parse(request.url);
|
||||
var opts = {
|
||||
host: parsed.hostname,
|
||||
port: parsed.port,
|
||||
path: parsed.path
|
||||
};
|
||||
|
||||
http.get(opts, function (res) {
|
||||
response.writeHead(res.statusCode, res.headers);
|
||||
res.on('data', function (data) {
|
||||
response.write(data)
|
||||
});
|
||||
res.on('end', function () {
|
||||
response.end();
|
||||
});
|
||||
});
|
||||
}).listen(4000, function () {
|
||||
var configBeforeRedirectCount = 0;
|
||||
axios.get('http://localhost:4444/', {
|
||||
proxy: {
|
||||
host: 'localhost',
|
||||
port: 4000
|
||||
},
|
||||
maxRedirects: totalRedirectCount,
|
||||
beforeRedirect: function (options) {
|
||||
configBeforeRedirectCount += 1;
|
||||
}
|
||||
}).then(function (res) {
|
||||
assert.equal(totalRedirectCount, configBeforeRedirectCount, 'should invoke config.beforeRedirect option on every redirect');
|
||||
assert.equal(totalRedirectCount + 1, proxyUseCount, 'should go through proxy on every redirect');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user