MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / stripPort

Function stripPort

packages/server/src/middleware/hostnames.ts:86–104  ·  view source on GitHub ↗
(host: string)

Source from the content-addressed store, hash-verified

84 * lowercased as-is — there is no unambiguous port to strip.
85 */
86export function stripPort(host: string): string {
87 if (host.startsWith('[')) {
88 const end = host.indexOf(']');
89 return (end === -1 ? host : host.slice(0, end + 1)).toLowerCase();
90 }
91 const firstColon = host.indexOf(':');
92 if (firstColon === -1) {
93 return host.toLowerCase();
94 }
95 const lastColon = host.lastIndexOf(':');
96 if (firstColon === lastColon) {
97 const after = host.slice(lastColon + 1);
98 if (after.length > 0 && /^\d+$/.test(after)) {
99 return host.slice(0, lastColon).toLowerCase();
100 }
101 }
102 // Multiple colons (bare IPv6) or a non-digit suffix — no port to strip.
103 return host.toLowerCase();
104}
105
106export function formatHostErrorMessage(host: string | undefined): string {
107 const normalizedHost = host === undefined || host.length === 0 ? undefined : stripPort(host);

Callers 4

hostnames.test.tsFile · 0.90
isOriginAllowedFunction · 0.90
formatHostErrorMessageFunction · 0.85
isAllowedHostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected