Skip to content

Commit

Permalink
🤖 Merge PR #68213 net: Support lookup of one address in `net.LookupFu…
Browse files Browse the repository at this point in the history
…nction` (`autoSelectFamily: false`) by @lefebvree

Update `net` LookupFunction to accept both `option.all` as truthy or
falsy, and return one address / family or an array of `LookupAddress`.
  • Loading branch information
lefebvree committed Feb 1, 2024
1 parent d4ededa commit 7315318
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 16 deletions.
4 changes: 2 additions & 2 deletions types/node/net.d.ts
Expand Up @@ -18,8 +18,8 @@ declare module "net" {
import * as dns from "node:dns";
type LookupFunction = (
hostname: string,
options: dns.LookupAllOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void,
options: dns.LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
) => void;
interface AddressInfo {
address: string;
Expand Down
5 changes: 5 additions & 0 deletions types/node/test/http.ts
Expand Up @@ -673,6 +673,11 @@ import * as url from "node:url";
cb(null, [{ address: "", family: 1 }]);
},
});
http.request({
lookup: (hostname, options, cb) => {
cb(null, "", 1);
},
});
}

{
Expand Down
5 changes: 5 additions & 0 deletions types/node/test/https.ts
Expand Up @@ -604,4 +604,9 @@ import * as url from "node:url";
cb(null, [{ address: "", family: 1 }]);
},
});
https.request({
lookup: (hostname, options, cb) => {
cb(null, "", 1);
},
});
}
28 changes: 26 additions & 2 deletions types/node/test/net.ts
@@ -1,5 +1,5 @@
import { Socket } from "node:dgram";
import { LookupAddress, LookupAllOptions } from "node:dns";
import { LookupAddress, LookupOptions } from "node:dns";
import * as net from "node:net";

{
Expand Down Expand Up @@ -70,6 +70,30 @@ import * as net from "node:net";
_socket.destroySoon();
}

{
// lookup callback can be either an array of LookupAddress or a single address and family
const tcpConnectLookupAllOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
callback(null, [{ address: "", family: 1 }]);
},
port: 80,
};
const tcpConnectLookupOneOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
callback(null, "", 1);
},
port: 80,
};
}

{
const constructorOpts: net.SocketConstructorOpts = {
fd: 1,
Expand Down Expand Up @@ -109,7 +133,7 @@ import * as net from "node:net";
localPort: 1234,
lookup: (
_hostname: string,
_options: LookupAllOptions,
_options: LookupOptions,
_callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
// nothing
Expand Down
4 changes: 2 additions & 2 deletions types/node/ts4.8/net.d.ts
Expand Up @@ -18,8 +18,8 @@ declare module "net" {
import * as dns from "node:dns";
type LookupFunction = (
hostname: string,
options: dns.LookupAllOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void,
options: dns.LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
) => void;
interface AddressInfo {
address: string;
Expand Down
5 changes: 5 additions & 0 deletions types/node/ts4.8/test/http.ts
Expand Up @@ -646,6 +646,11 @@ import * as url from "node:url";
cb(null, [{ address: "", family: 1 }]);
},
});
http.request({
lookup: (hostname, options, cb) => {
cb(null, "", 1);
},
});
}

{
Expand Down
5 changes: 5 additions & 0 deletions types/node/ts4.8/test/https.ts
Expand Up @@ -604,4 +604,9 @@ import * as url from "node:url";
cb(null, [{ address: "", family: 1 }]);
},
});
https.request({
lookup: (hostname, options, cb) => {
cb(null, "", 1);
},
});
}
28 changes: 26 additions & 2 deletions types/node/ts4.8/test/net.ts
@@ -1,5 +1,5 @@
import { Socket } from "node:dgram";
import { LookupAddress, LookupAllOptions } from "node:dns";
import { LookupAddress, LookupOptions } from "node:dns";
import * as net from "node:net";

{
Expand Down Expand Up @@ -70,6 +70,30 @@ import * as net from "node:net";
_socket.destroySoon();
}

{
// lookup callback can be either an array of LookupAddress or a single address and family
const tcpConnectLookupAllOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
callback(null, [{ address: "", family: 1 }]);
},
port: 80,
};
const tcpConnectLookupOneOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
callback(null, "", 1);
},
port: 80,
};
}

{
const constructorOpts: net.SocketConstructorOpts = {
fd: 1,
Expand Down Expand Up @@ -109,7 +133,7 @@ import * as net from "node:net";
localPort: 1234,
lookup: (
_hostname: string,
_options: LookupAllOptions,
_options: LookupOptions,
_callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
// nothing
Expand Down
4 changes: 2 additions & 2 deletions types/node/v18/net.d.ts
Expand Up @@ -18,8 +18,8 @@ declare module "net" {
import * as dns from "node:dns";
type LookupFunction = (
hostname: string,
options: dns.LookupOneOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
options: dns.LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
) => void;
interface AddressInfo {
address: string;
Expand Down
28 changes: 26 additions & 2 deletions types/node/v18/test/net.ts
@@ -1,5 +1,5 @@
import { Socket } from "node:dgram";
import { LookupOneOptions } from "node:dns";
import { LookupAddress, LookupOptions } from "node:dns";
import * as net from "node:net";

{
Expand Down Expand Up @@ -70,6 +70,30 @@ import * as net from "node:net";
_socket.destroySoon();
}

{
// lookup callback can be either an array of LookupAddress or a single address and family
const tcpConnectLookupAllOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
callback(null, [{ address: "", family: 1 }]);
},
port: 80,
};
const tcpConnectLookupOneOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
callback(null, "", 1);
},
port: 80,
};
}

{
const constructorOpts: net.SocketConstructorOpts = {
fd: 1,
Expand Down Expand Up @@ -109,7 +133,7 @@ import * as net from "node:net";
localPort: 1234,
lookup: (
_hostname: string,
_options: LookupOneOptions,
_options: LookupOptions,
_callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
// nothing
Expand Down
4 changes: 2 additions & 2 deletions types/node/v18/ts4.8/net.d.ts
Expand Up @@ -18,8 +18,8 @@ declare module "net" {
import * as dns from "node:dns";
type LookupFunction = (
hostname: string,
options: dns.LookupOneOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
options: dns.LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
) => void;
interface AddressInfo {
address: string;
Expand Down
28 changes: 26 additions & 2 deletions types/node/v18/ts4.8/test/net.ts
@@ -1,5 +1,5 @@
import { Socket } from "node:dgram";
import { LookupOneOptions } from "node:dns";
import { LookupAddress, LookupOptions } from "node:dns";
import * as net from "node:net";

{
Expand Down Expand Up @@ -70,6 +70,30 @@ import * as net from "node:net";
_socket.destroySoon();
}

{
// lookup callback can be either an array of LookupAddress or a single address and family
const tcpConnectLookupAllOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
): void => {
callback(null, [{ address: "", family: 1 }]);
},
port: 80,
};
const tcpConnectLookupOneOpts: net.TcpSocketConnectOpts = {
lookup: (
_hostname: string,
_options: LookupOptions,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
callback(null, "", 1);
},
port: 80,
};
}

{
const constructorOpts: net.SocketConstructorOpts = {
fd: 1,
Expand Down Expand Up @@ -109,7 +133,7 @@ import * as net from "node:net";
localPort: 1234,
lookup: (
_hostname: string,
_options: LookupOneOptions,
_options: LookupOptions,
_callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
): void => {
// nothing
Expand Down

0 comments on commit 7315318

Please sign in to comment.