MCPcopy
hub / github.com/tinyhttp/tinyhttp / getProtocol

Function getProtocol

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

Source from the content-addressed store, hash-verified

31 middleware.find(({ handler }) => typeof handler === 'function' && handler.name === h.name)
32
33export const getProtocol = (req: Request): Protocol => {
34 const proto = req.connection.encrypted ? 'https' : 'http'
35
36 if (!trustRemoteAddress(req)) return proto
37
38 const header = (req.headers['X-Forwarded-Proto'] as string) || proto
39
40 const index = header.indexOf(',')
41
42 return index !== -1 ? header.substring(0, index).trim() : header.trim()
43}
44
45export const getHostname = (req: Request): string | undefined => {
46 let host: string = req.get('X-Forwarded-Host') as string

Callers 1

extendMiddlewareFunction · 0.90

Calls 1

trustRemoteAddressFunction · 0.85

Tested by

no test coverage detected