|
1 | | -import {IPAddress, IPv4, IPv6} from "@cldn/ip"; |
| 1 | +import {IP, IPAddress, IPv4, IPv6} from "@cldn/ip"; |
2 | 2 | import {Multipart} from "multipart-ts"; |
3 | 3 | import http, {OutgoingHttpHeader} from "node:http"; |
4 | 4 | import stream from "node:stream"; |
@@ -54,14 +54,14 @@ export class Request<A> { |
54 | 54 | /** |
55 | 55 | * The IP address of the request sender (last peer). This might be a proxy. |
56 | 56 | */ |
57 | | - public readonly originalIp: IPv4 | IPv6; |
| 57 | + public readonly originalIp: IP; |
58 | 58 |
|
59 | 59 | /** |
60 | 60 | * IP address of client (first peer). If the request originated from a trusted proxy, this will be the client IP |
61 | 61 | * indicated by the proxy. Otherwise, if the proxy specifies no client IP, or the proxy is untrusted, this will be |
62 | 62 | * the proxy IP and equivalent to {@link Request#originalIp}. |
63 | 63 | */ |
64 | | - public readonly ip: IPv4 | IPv6; |
| 64 | + public readonly ip: IP; |
65 | 65 |
|
66 | 66 | /** |
67 | 67 | * The {@link Server} from which this request was received. |
@@ -141,7 +141,7 @@ export class Request<A> { |
141 | 141 | if (remoteAddress === undefined) |
142 | 142 | throw new Request.SocketClosedError(); |
143 | 143 | const ip = IPAddress.fromString(remoteAddress); |
144 | | - const isTrustedProxy = server.trustedProxies.has(ip); |
| 144 | + const isTrustedProxy = server.trustedProxies.contains(ip); |
145 | 145 |
|
146 | 146 | const headers = Request.headersFromNodeDict(incomingMessage.headers); |
147 | 147 |
|
@@ -207,11 +207,11 @@ export class Request<A> { |
207 | 207 | * Extract client IP, protocol, and host, from the information provided by a trusted proxy. |
208 | 208 | * @param headers The HTTP headers sent by a trusted proxy. |
209 | 209 | */ |
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"} { |
211 | 211 | if (headers.has("forwarded")) { |
212 | 212 | const forwarded = headers.get("forwarded")!.split(",")[0]!.trim(); |
213 | 213 | const forwardedPairs = forwarded.split(";"); |
214 | | - let ip: IPv4 | IPv6 | undefined = undefined; |
| 214 | + let ip: IP | undefined = undefined; |
215 | 215 | let host: string | undefined = undefined; |
216 | 216 | let protocol: "http" | "https" | undefined = undefined; |
217 | 217 | for (const pair of forwardedPairs) { |
@@ -254,7 +254,7 @@ export class Request<A> { |
254 | 254 | return {ip, host, protocol}; |
255 | 255 | } |
256 | 256 |
|
257 | | - let ip: IPv4 | IPv6 | undefined = undefined; |
| 257 | + let ip: IP | undefined = undefined; |
258 | 258 | if (headers.has("x-forwarded-for")) { |
259 | 259 | const address = headers.get("x-forwarded-for")!.split(",")[0]!; |
260 | 260 | ip = IPAddress.fromString(address.trim()); |
|
0 commit comments