(req: Request)
| 43 | } |
| 44 | |
| 45 | export 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 | |
| 58 | export 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 |
no test coverage detected