-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enclose ipv6 host with brackets on client request (#1243)
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* joinHostPort combines host and port into a network address of the | ||
* form "host:port". If host contains a colon, as found in literal | ||
* IPv6 addresses, then JoinHostPort returns "[host]:port". | ||
* | ||
* @param host | ||
* @param port | ||
* @returns Cleaned up host | ||
* @internal | ||
*/ | ||
export function joinHostPort(host: string, port?: number): string { | ||
if (port === undefined) { | ||
return host | ||
} | ||
|
||
// We assume that host is a literal IPv6 address if host has | ||
// colons. | ||
if (host.includes(':')) { | ||
return `[${host}]:${port.toString()}` | ||
} | ||
|
||
return `${host}:${port.toString()}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters