mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
feat(dns): added support for a custom lookup function; (#5339)
This commit is contained in:
@@ -56,6 +56,8 @@ var noop = ()=> {};
|
||||
|
||||
const LOCAL_SERVER_URL = 'http://localhost:4444';
|
||||
|
||||
const SERVER_HANDLER_STREAM_ECHO = (req, res) => req.pipe(res);
|
||||
|
||||
function startHTTPServer(options) {
|
||||
|
||||
const {handler, useBuffering = false, rate = undefined, port = 4444} = typeof options === 'function' ? {
|
||||
@@ -2117,4 +2119,63 @@ describe('supports http with nodejs', function () {
|
||||
|
||||
assert.strictEqual(data, '/?foo');
|
||||
});
|
||||
|
||||
describe('DNS', function() {
|
||||
it('should support custom DNS lookup function', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
|
||||
let isCalled = false;
|
||||
|
||||
const {data} = await axios.post(`http://fake-name.axios:4444`, payload,{
|
||||
lookup: (hostname, opt, cb) => {
|
||||
isCalled = true;
|
||||
cb(null, '127.0.0.1', 4);
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(isCalled);
|
||||
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support custom DNS lookup function (async)', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
|
||||
let isCalled = false;
|
||||
|
||||
const {data} = await axios.post(`http://fake-name.axios:4444`, payload,{
|
||||
lookup: async (hostname, opt) => {
|
||||
isCalled = true;
|
||||
return ['127.0.0.1', 4];
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(isCalled);
|
||||
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support custom DNS lookup function that returns only IP address (async)', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
|
||||
let isCalled = false;
|
||||
|
||||
const {data} = await axios.post(`http://fake-name.axios:4444`, payload,{
|
||||
lookup: async (hostname, opt) => {
|
||||
isCalled = true;
|
||||
return '127.0.0.1';
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(isCalled);
|
||||
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user