| 506 | }; |
| 507 | |
| 508 | function getHostname(self, rest, hostname, url) { |
| 509 | for (let i = 0; i < hostname.length; ++i) { |
| 510 | const code = hostname.charCodeAt(i); |
| 511 | const isValid = (code !== CHAR_FORWARD_SLASH && |
| 512 | code !== CHAR_BACKWARD_SLASH && |
| 513 | code !== CHAR_HASH && |
| 514 | code !== CHAR_QUESTION_MARK && |
| 515 | code !== CHAR_COLON); |
| 516 | |
| 517 | if (!isValid) { |
| 518 | // If leftover starts with :, then it represents an invalid port. |
| 519 | if (code === CHAR_COLON) { |
| 520 | throw new ERR_INVALID_ARG_VALUE('url', 'Invalid port in url', url); |
| 521 | } |
| 522 | self.hostname = hostname.slice(0, i); |
| 523 | return `/${hostname.slice(i)}${rest}`; |
| 524 | } |
| 525 | } |
| 526 | return rest; |
| 527 | } |
| 528 | |
| 529 | // Escaped characters. Use empty strings to fill up unused entries. |
| 530 | // Using Array is faster than Object/Map |