mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
fix(dns): fixed lookup function decorator to work properly in node v20; (#6011)
This commit is contained in:
@@ -20,7 +20,7 @@ import axios, {
|
||||
all,
|
||||
isCancel,
|
||||
isAxiosError,
|
||||
spread
|
||||
spread, AddressFamily
|
||||
} from 'axios';
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
@@ -574,7 +574,7 @@ axios.get('/user', {
|
||||
|
||||
{
|
||||
// getAdapter
|
||||
|
||||
|
||||
getAdapter(axios.create().defaults.adapter);
|
||||
getAdapter(undefined);
|
||||
getAdapter([]);
|
||||
@@ -658,7 +658,7 @@ for (const [header, value] of headers) {
|
||||
|
||||
// lookup
|
||||
axios.get('/user', {
|
||||
lookup: (hostname: string, opt: object, cb: (err: Error | null, address: string, family: number) => void) => {
|
||||
lookup: (hostname: string, opt: object, cb: (err: Error | null, address: string, family: AddressFamily) => void) => {
|
||||
cb(null, '127.0.0.1', 4);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2122,7 +2122,7 @@ describe('supports http with nodejs', function () {
|
||||
});
|
||||
|
||||
describe('DNS', function() {
|
||||
it('should support custom DNS lookup function', async function () {
|
||||
it('should support a custom DNS lookup function', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
@@ -2141,7 +2141,26 @@ describe('supports http with nodejs', function () {
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support custom DNS lookup function (async)', async function () {
|
||||
it('should support a custom DNS lookup function with address entry passing', 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, {address: '127.0.0.1', family: 4});
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(isCalled);
|
||||
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support a custom DNS lookup function (async)', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
@@ -2160,7 +2179,26 @@ describe('supports http with nodejs', function () {
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support custom DNS lookup function that returns only IP address (async)', async function () {
|
||||
it('should support a custom DNS lookup function with address entry (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 {address: '127.0.0.1', family: 4};
|
||||
}
|
||||
});
|
||||
|
||||
assert.ok(isCalled);
|
||||
|
||||
assert.strictEqual(data, payload);
|
||||
});
|
||||
|
||||
it('should support a custom DNS lookup function that returns only IP address (async)', async function () {
|
||||
server = await startHTTPServer(SERVER_HANDLER_STREAM_ECHO);
|
||||
|
||||
const payload = 'test';
|
||||
|
||||
Reference in New Issue
Block a user