MCPcopy
hub / github.com/tinyhttp/tinyhttp / getHostname

Function getHostname

packages/app/src/request.ts:45–56  ·  view source on GitHub ↗
(req: Request)

Source from the content-addressed store, hash-verified

43}
44
45export const getHostname = (req: Request): string | undefined => {
46 let host: string = req.get('X-Forwarded-Host') as string
47
48 if (!host || !trustRemoteAddress(req)) host = req.get('Host') as string
49
50 if (!host) return
51
52 // IPv6 literal support
53 const index = host.indexOf(':', host[0] === '[' ? host.indexOf(']') + 1 : 0)
54
55 return index !== -1 ? host.substring(0, index) : host
56}
57
58export const getIP = (req: Pick<IncomingMessage, 'headers' | 'connection'>): string | undefined =>
59 proxyAddr(req, trustRemoteAddress(req)).replace(/^.*:/, '') // striping the redundant prefix addeded by OS to IPv4 address

Callers 2

extendMiddlewareFunction · 0.90
getSubdomainsFunction · 0.85

Calls 2

trustRemoteAddressFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected