mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:51:24 +00:00
refactor(net): share hostname normalization
This commit is contained in:
7
src/infra/net/hostname.ts
Normal file
7
src/infra/net/hostname.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function normalizeHostname(hostname: string): string {
|
||||
const normalized = hostname.trim().toLowerCase().replace(/\.$/, "");
|
||||
if (normalized.startsWith("[") && normalized.endsWith("]")) {
|
||||
return normalized.slice(1, -1);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { lookup as dnsLookupCb, type LookupAddress } from "node:dns";
|
||||
import { lookup as dnsLookup } from "node:dns/promises";
|
||||
import { Agent, type Dispatcher } from "undici";
|
||||
import { normalizeHostname } from "./hostname.js";
|
||||
|
||||
type LookupCallback = (
|
||||
err: NodeJS.ErrnoException | null,
|
||||
@@ -25,14 +26,6 @@ export type SsrFPolicy = {
|
||||
|
||||
const BLOCKED_HOSTNAMES = new Set(["localhost", "metadata.google.internal"]);
|
||||
|
||||
function normalizeHostname(hostname: string): string {
|
||||
const normalized = hostname.trim().toLowerCase().replace(/\.$/, "");
|
||||
if (normalized.startsWith("[") && normalized.endsWith("]")) {
|
||||
return normalized.slice(1, -1);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function normalizeHostnameSet(values?: string[]): Set<string> {
|
||||
if (!values || values.length === 0) {
|
||||
return new Set<string>();
|
||||
|
||||
Reference in New Issue
Block a user