Skip to content

Commit 7bb1f40

Browse files
authored
Bump @cldn/ip from 1.0.4 to 2.0.1 (#108)
2 parents a87804d + 3403fc8 commit 7bb1f40

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"typescript": "^5.8.2"
4141
},
4242
"dependencies": {
43-
"@cldn/ip": "^1.0.3",
43+
"@cldn/ip": "^2.0.1",
4444
"multipart-ts": "^1.3.2"
4545
}
4646
}

src/Request.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {IPAddress, IPv4, IPv6} from "@cldn/ip";
1+
import {IP, IPAddress, IPv4, IPv6} from "@cldn/ip";
22
import {Multipart} from "multipart-ts";
33
import http, {OutgoingHttpHeader} from "node:http";
44
import stream from "node:stream";
@@ -54,14 +54,14 @@ export class Request<A> {
5454
/**
5555
* The IP address of the request sender (last peer). This might be a proxy.
5656
*/
57-
public readonly originalIp: IPv4 | IPv6;
57+
public readonly originalIp: IP;
5858

5959
/**
6060
* IP address of client (first peer). If the request originated from a trusted proxy, this will be the client IP
6161
* indicated by the proxy. Otherwise, if the proxy specifies no client IP, or the proxy is untrusted, this will be
6262
* the proxy IP and equivalent to {@link Request#originalIp}.
6363
*/
64-
public readonly ip: IPv4 | IPv6;
64+
public readonly ip: IP;
6565

6666
/**
6767
* The {@link Server} from which this request was received.
@@ -141,7 +141,7 @@ export class Request<A> {
141141
if (remoteAddress === undefined)
142142
throw new Request.SocketClosedError();
143143
const ip = IPAddress.fromString(remoteAddress);
144-
const isTrustedProxy = server.trustedProxies.has(ip);
144+
const isTrustedProxy = server.trustedProxies.contains(ip);
145145

146146
const headers = Request.headersFromNodeDict(incomingMessage.headers);
147147

@@ -207,11 +207,11 @@ export class Request<A> {
207207
* Extract client IP, protocol, and host, from the information provided by a trusted proxy.
208208
* @param headers The HTTP headers sent by a trusted proxy.
209209
*/
210-
private static getClientInfoFromTrustedProxy(headers: Headers): {ip?: IPv4 | IPv6, host?: string, protocol?: "http" | "https"} {
210+
private static getClientInfoFromTrustedProxy(headers: Headers): {ip?: IP, host?: string, protocol?: "http" | "https"} {
211211
if (headers.has("forwarded")) {
212212
const forwarded = headers.get("forwarded")!.split(",")[0]!.trim();
213213
const forwardedPairs = forwarded.split(";");
214-
let ip: IPv4 | IPv6 | undefined = undefined;
214+
let ip: IP | undefined = undefined;
215215
let host: string | undefined = undefined;
216216
let protocol: "http" | "https" | undefined = undefined;
217217
for (const pair of forwardedPairs) {
@@ -254,7 +254,7 @@ export class Request<A> {
254254
return {ip, host, protocol};
255255
}
256256

257-
let ip: IPv4 | IPv6 | undefined = undefined;
257+
let ip: IP | undefined = undefined;
258258
if (headers.has("x-forwarded-for")) {
259259
const address = headers.get("x-forwarded-for")!.split(",")[0]!;
260260
ip = IPAddress.fromString(address.trim());

src/Server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Network} from "@cldn/ip";
1+
import {Network, SubnetList} from "@cldn/ip";
22
import EventEmitter from "node:events";
33
import http from "node:http";
44
import packageJson from "./package.json" with {type: "json"};
@@ -36,8 +36,9 @@ class Server<A> extends EventEmitter<Server.Events> {
3636
private readonly port?: number;
3737
private readonly copyOrigin: boolean;
3838
private readonly handleConditionalRequests: boolean;
39+
3940
/**
40-
* The network of remote addresses of proxies to trust/
41+
* The network of remote addresses of proxies to trust.
4142
*/
4243
public readonly trustedProxies: Network;
4344

@@ -59,7 +60,7 @@ class Server<A> extends EventEmitter<Server.Events> {
5960
this.copyOrigin = options?.copyOrigin ?? false;
6061
this.handleConditionalRequests = options?.handleConditionalRequests ?? true;
6162
this._authenticators = options?.authenticators ?? [];
62-
this.trustedProxies = options?.trustedProxies ?? new Network();
63+
this.trustedProxies = options?.trustedProxies ?? new SubnetList();
6364

6465
if (this.port !== undefined) this.listen(this.port).then();
6566

0 commit comments

Comments
 (0)