Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Support lookup of one address in net.LookupFunction (autoSelectFamily: false) #68213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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