hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f5f85070682d40617b3679cf98e4e8f349cfd83d
parent 349cf4d9fff3c30c07e473d86bb7573e4d6c7fa3
Author: Tom Lebreux <me@tomlebreux.com>
Date:   Mon, 30 May 2022 17:51:31 -0400

net::uri: surround ipv6 host with [ and ]

Signed-off-by: Tom Lebreux <me@tomlebreux.com>

Diffstat:
Mnet/uri/fmt.ha | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/uri/fmt.ha b/net/uri/fmt.ha @@ -30,7 +30,7 @@ export fn fmt(out: io::handle, u: *const uri) (size | io::error) = { if (!slashes_w) { n += fmt::fprint(out, "//")?; }; - n += ip::fmt(out, addr)?; + n += fmtaddr(out, addr)?; }; if (u.port != 0) { n += fmt::fprintf(out, ":{}", u.port)?; @@ -47,6 +47,19 @@ export fn fmt(out: io::handle, u: *const uri) (size | io::error) = { return n; }; +fn fmtaddr(out: io::handle, addr: ip::addr) (size | io::error) = { + let n = 0z; + match (addr) { + case let addr: ip::addr4 => + n += ip::fmt(out, addr)?; + case let addr: ip::addr6 => + n += fmt::fprintf(out, "[")?; + n += ip::fmt(out, addr)?; + n += fmt::fprintf(out, "]")?; + }; + return n; +}; + fn percent_encode(out: io::handle, src: str) (size | io::error) = { let iter = strings::iter(src); let n = 0z;