MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / trustRemoteAddress

Function trustRemoteAddress

packages/app/src/request.ts:16–28  ·  view source on GitHub ↗
({ connection }: Pick<IncomingMessage, 'headers' | 'connection'>)

Source from the content-addressed store, hash-verified

14export { getURLParams } from '@tinyhttp/req'
15
16const trustRemoteAddress = ({ connection }: Pick<IncomingMessage, 'headers' | 'connection'>) => {
17 const val = connection.remoteAddress
18
19 if (typeof val === 'function') return val
20
21 if (typeof val === 'boolean' && val === true) return () => true
22
23 if (typeof val === 'number') return (_: unknown, i: number) => (val ? i < val : undefined)
24
25 if (typeof val === 'string') return compile(val.split(',').map((x) => x.trim()))
26
27 return compile(val || [])
28}
29
30export const getRouteFromApp = ({ middleware }: App, h: Handler<Request, Response>) =>
31 middleware.find(({ handler }) => typeof handler === 'function' && handler.name === h.name)

Callers 4

getProtocolFunction · 0.85
getHostnameFunction · 0.85
getIPFunction · 0.85
getIPsFunction · 0.85

Calls 1

compileFunction · 0.90

Tested by

no test coverage detected