diff options
Diffstat (limited to 'src/url.zig')
-rw-r--r-- | src/url.zig | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/url.zig b/src/url.zig index 11959636e..90bc002ba 100644 --- a/src/url.zig +++ b/src/url.zig @@ -103,7 +103,7 @@ pub const URL = struct { pub const HostFormatter = struct { host: string, - port: string = "", + port: ?u16 = null, is_https: bool = false, pub fn format(formatter: HostFormatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { @@ -114,11 +114,10 @@ pub const URL = struct { try writer.writeAll(formatter.host); - const is_port_optional = (formatter.is_https and (formatter.port.len == 0 or strings.eqlComptime(formatter.port, "443"))) or - (!formatter.is_https and (formatter.port.len == 0 or strings.eqlComptime(formatter.port, "80"))); + const is_port_optional = formatter.port == null or (formatter.is_https and formatter.port == 443) or + (!formatter.is_https and formatter.port == 80); if (!is_port_optional) { - try writer.writeAll(":"); - try writer.writeAll(formatter.port); + try writer.print(":{d}", .{formatter.port.?}); return; } } @@ -126,7 +125,7 @@ pub const URL = struct { pub fn displayHost(this: *const URL) HostFormatter { return HostFormatter{ .host = if (this.host.len > 0) this.host else this.displayHostname(), - .port = this.port, + .port = if (this.port.len > 0) this.getPort() else null, .is_https = this.isHTTPS(), }; } |