* Parse the `:1234` tail of a `Host` header. * * @returns the port, `undefined` for an empty suffix, or `null` when the suffix * is present but not a plain port number.
(suffix: string)
| 144 | * is present but not a plain port number. |
| 145 | */ |
| 146 | function parsePortSuffix(suffix: string): number | undefined | null { |
| 147 | if (suffix === '') return undefined; |
| 148 | if (!suffix.startsWith(':')) return null; |
| 149 | const digits = suffix.slice(1); |
| 150 | if (!/^\d{1,5}$/.test(digits)) return null; |
| 151 | const port = Number(digits); |
| 152 | return port >= 0 && port <= 65535 ? port : null; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Whether a request's `Host` header names this loopback server. |
no test coverage detected