diff options
Diffstat (limited to 'src/query_string_map.zig')
-rw-r--r-- | src/query_string_map.zig | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/query_string_map.zig b/src/query_string_map.zig index 1bac8f5ce..ddf90750f 100644 --- a/src/query_string_map.zig +++ b/src/query_string_map.zig @@ -20,6 +20,37 @@ pub const URL = struct { username: string = "", port_was_automatically_set: bool = false, + pub fn isDomainName(this: *const URL) bool { + for (this.hostname) |c, i| { + switch (c) { + '0'...'9', '.', ':' => {}, + else => { + return true; + }, + } + } + + return false; + } + + pub fn isLocalhost(this: *const URL) bool { + return this.hostname.len == 0 or strings.eqlComptime(this.hostname, "localhost") or strings.eqlComptime(this.hostname, "0.0.0.0"); + } + + pub fn getIPv4Address(this: *const URL) ?std.x.net.ip.Address.IPv4 { + return (if (this.hostname.length > 0) + std.x.os.IPv4.parse(this.hostname) + else + std.x.os.IPv4.parse(this.href)) catch return null; + } + + pub fn getIPv6Address(this: *const URL) ?std.x.net.ip.Address.IPv6 { + return (if (this.hostname.length > 0) + std.x.os.IPv6.parse(this.hostname) + else + std.x.os.IPv6.parse(this.href)) catch return null; + } + pub fn displayProtocol(this: *const URL) string { if (this.protocol.len > 0) { return this.protocol; @@ -34,6 +65,10 @@ pub const URL = struct { return "http"; } + pub inline fn isHTTPS(this: *const URL) bool { + return strings.eqlComptime(this.protocol, "https"); + } + pub fn displayHostname(this: *const URL) string { if (this.hostname.len > 0) { return this.hostname; @@ -50,6 +85,10 @@ pub const URL = struct { return std.fmt.parseInt(u16, this.port, 10) catch null; } + pub fn getPortAuto(this: *const URL) u16 { + return this.getPort() orelse (if (this.isHTTPS()) @as(u16, 443) else @as(u16, 80)); + } + pub fn hasValidPort(this: *const URL) bool { return (this.getPort() orelse 0) > 1; } |