MCPcopy Create free account
hub / github.com/continuedev/continue / patternMatchesHostname

Function patternMatchesHostname

packages/fetch/src/util.ts:53–89  ·  view source on GitHub ↗
(hostname: string, pattern: string)

Source from the content-addressed store, hash-verified

51}
52
53export function patternMatchesHostname(hostname: string, pattern: string) {
54 // Split hostname and pattern to separate hostname and port
55 const [hostnameWithoutPort, hostnamePort] = hostname.toLowerCase().split(":");
56 const [patternWithoutPort, patternPort] = pattern.toLowerCase().split(":");
57
58 // If pattern specifies a port but hostname doesn't match it, no match
59 if (patternPort && (!hostnamePort || hostnamePort !== patternPort)) {
60 return false;
61 }
62
63 // Now compare just the hostname parts
64
65 // exact match
66 if (patternWithoutPort === hostnameWithoutPort) {
67 return true;
68 }
69 // wildcard domain match (*.example.com)
70 if (
71 patternWithoutPort.startsWith("*.") &&
72 hostnameWithoutPort.endsWith(patternWithoutPort.substring(1))
73 ) {
74 return true;
75 }
76 // Domain suffix match (.example.com)
77 if (
78 patternWithoutPort.startsWith(".") &&
79 hostnameWithoutPort.endsWith(patternWithoutPort.slice(1))
80 ) {
81 return true;
82 }
83
84 // TODO IP address ranges
85
86 // TODO CIDR notation
87
88 return false;
89}
90
91/**
92 * Checks if a hostname should bypass proxy based on NO_PROXY environment variable

Callers 2

shouldBypassProxyFunction · 0.85
util.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected