chore(repo): prune dead code and duplicate abstractions (#3413)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-12 13:09:42 +02:00
1 parent c17091768c
commit c9fdf8fead
2937 files changed
+42233 -176793

No files matched your search

+5 -36
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {IpAddressFamily, ParsedIpAddress} from '@fluxer/ip_utils/src/IpAddress';
import type {ParsedIpAddress} from '@fluxer/ip_utils/src/IpAddress';
import {parseIpAddress} from '@fluxer/ip_utils/src/IpAddress';
interface ClientIpExtractionOptions {
@@ -8,14 +8,6 @@ interface ClientIpExtractionOptions {
clientIpHeaderName?: string;
}
type ClientIpSource = 'client-ip-header';
interface ExtractedClientIp {
ip: string;
source: ClientIpSource;
ipVersion: IpAddressFamily;
}
export class MissingClientIpError extends Error {
readonly code = 'FORBIDDEN';
readonly status = 403;
@@ -26,10 +18,6 @@ export class MissingClientIpError extends Error {
}
}
interface HeaderReader {
get(name: string): string | null;
}
const DEFAULT_CLIENT_IP_HEADER_NAME = 'x-forwarded-for';
function normalizeHeaderName(headerName: string): string {
@@ -47,32 +35,13 @@ function parseClientIpHeaderValue(value: string | null): ParsedIpAddress | null
return parseIpAddress(value.split(',', 1)[0]);
}
function extractClientIpDetailsFromReader(
headerReader: HeaderReader,
options?: ClientIpExtractionOptions,
): ExtractedClientIp | null {
export function extractClientIp(req: Request, options?: ClientIpExtractionOptions): string | null {
if (!options?.trustClientIpHeader) {
return null;
}
const headerName = resolveClientIpHeaderName(options.clientIpHeaderName);
const clientIpHeader = parseClientIpHeaderValue(headerReader.get(headerName));
if (clientIpHeader) {
return {
ip: clientIpHeader.normalized,
source: 'client-ip-header',
ipVersion: clientIpHeader.family,
};
}
return null;
}
export function extractClientIpDetails(req: Request, options?: ClientIpExtractionOptions): ExtractedClientIp | null {
return extractClientIpDetailsFromReader(req.headers, options);
}
export function extractClientIp(req: Request, options?: ClientIpExtractionOptions): string | null {
const extracted = extractClientIpDetails(req, options);
return extracted?.ip ?? null;
return (
parseClientIpHeaderValue(req.headers.get(resolveClientIpHeaderName(options.clientIpHeaderName)))?.normalized ?? null
);
}
export function requireClientIp(req: Request, options?: ClientIpExtractionOptions): string {