MCPcopy Create free account
hub / github.com/cameri/nostream / getTrustedForwardedPathPrefix

Function getTrustedForwardedPathPrefix

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

Source from the content-addressed store, hash-verified

96}
97
98const getTrustedForwardedPathPrefix = (request: IncomingMessage, settings: Settings): string => {
99 const socketAddress = request.socket?.remoteAddress
100 if (typeof socketAddress !== 'string' || !isTrustedProxy(socketAddress, settings)) {
101 return ''
102 }
103
104 const rawHeader = request.headers?.['x-forwarded-prefix']
105 const rawPrefix = Array.isArray(rawHeader) ? rawHeader[0] : rawHeader
106
107 return normalizePathPrefix(rawPrefix)
108}
109
110export const getPublicPathPrefix = (request: IncomingMessage, settings: Settings): string => {
111 return getTrustedForwardedPathPrefix(request, settings) || getRelayUrlPathPrefix(settings.info?.relay_url)

Callers 1

getPublicPathPrefixFunction · 0.85

Calls 2

isTrustedProxyFunction · 0.85
normalizePathPrefixFunction · 0.85

Tested by

no test coverage detected