diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-07-13 05:56:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-13 00:56:45 -0400 |
commit | 63edeb1c36bfcea278c248e8be92f7dbb75f7671 (patch) | |
tree | dbf47efb616fbe896e2c7b559f186af8150ab5e7 /std | |
parent | 4aeac64ecd82d5953bdb92916248f5f7352be4f4 (diff) |
fix(cli/js/web/url): Implement IPv4 hostname parsing (#6707)
Diffstat (limited to 'std')
-rw-r--r-- | std/http/server.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/std/http/server.ts b/std/http/server.ts index 5908fcf9a..b1ffed96b 100644 --- a/std/http/server.ts +++ b/std/http/server.ts @@ -248,7 +248,8 @@ export type HTTPOptions = Omit<Deno.ListenOptions, "transport">; export function _parseAddrFromStr(addr: string): HTTPOptions { let url: URL; try { - url = new URL(`http://${addr}`); + const host = addr.startsWith(":") ? `0.0.0.0${addr}` : addr; + url = new URL(`http://${host}`); } catch { throw new TypeError("Invalid address."); } @@ -263,7 +264,7 @@ export function _parseAddrFromStr(addr: string): HTTPOptions { } return { - hostname: url.hostname == "" ? "0.0.0.0" : url.hostname, + hostname: url.hostname, port: url.port === "" ? 80 : Number(url.port), }; } |