MCPcopy Index your code
hub / github.com/cameri/nostream / getRemoteAddress

Function getRemoteAddress

src/utils/http.ts:41–63  ·  view source on GitHub ↗
(request: IncomingMessage, settings: Settings)

Source from the content-addressed store, hash-verified

39}
40
41export const getRemoteAddress = (request: IncomingMessage, settings: Settings): string => {
42 warnIfDeprecatedRemoteIpHeaderIsConfigured(settings)
43
44 const header = settings.network?.remoteIpHeader as string
45
46 const trustedProxies = settings.network?.trustedProxies
47 if (header && (!Array.isArray(trustedProxies) || trustedProxies.length === 0)) {
48 logger.warn('WARNING: network.remoteIpHeader is set but network.trustedProxies is empty. Forwarded headers will be ignored. Add your proxy IP to network.trustedProxies.')
49 }
50
51 const rawHeaderAddress = header ? request.headers[header] : undefined
52 const headerAddress = Array.isArray(rawHeaderAddress) ? rawHeaderAddress[0] : rawHeaderAddress
53 const socketAddress = request.socket.remoteAddress
54
55 const trustedProxy = typeof socketAddress === 'string'
56 && isTrustedProxy(socketAddress, settings)
57
58 const result = trustedProxy && typeof headerAddress === 'string'
59 ? headerAddress
60 : socketAddress
61
62 return (result as string).split(',')[0].trim()
63}
64
65const normalizePathPrefix = (pathPrefix: string | undefined): string => {
66 if (typeof pathPrefix !== 'string') {

Callers 9

http.spec.tsFile · 0.90
handleRequestMethod · 0.90
handleRequestMethod · 0.90
handleRequestMethod · 0.90
isRateLimitedMethod · 0.90
isRateLimitedMethod · 0.90
constructorMethod · 0.90
onConnectionMethod · 0.90
rateLimiterMiddlewareFunction · 0.90

Calls 2

isTrustedProxyFunction · 0.85

Tested by

no test coverage detected