From bd9f137b1bfb5bc3b215515ff9305e70a638daf9 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 29 Aug 2021 21:48:14 -0700 Subject: latest Former-commit-id: 096ec1222ad723d006b0151f10cb0c1b95e2bfd3 --- src/query_string_map.zig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/query_string_map.zig') diff --git a/src/query_string_map.zig b/src/query_string_map.zig index e9e1f2e6d..1bac8f5ce 100644 --- a/src/query_string_map.zig +++ b/src/query_string_map.zig @@ -18,9 +18,30 @@ pub const URL = struct { search: string = "", searchParams: ?QueryStringMap = null, username: string = "", - port_was_automatically_set: bool = false, + pub fn displayProtocol(this: *const URL) string { + if (this.protocol.len > 0) { + return this.protocol; + } + + if (this.getPort()) |port| { + if (port == 443) { + return "https"; + } + } + + return "http"; + } + + pub fn displayHostname(this: *const URL) string { + if (this.hostname.len > 0) { + return this.hostname; + } + + return "localhost"; + } + pub fn hasHTTPLikeProtocol(this: *const URL) bool { return strings.eqlComptime(this.protocol, "http") or strings.eqlComptime(this.protocol, "https"); } -- cgit v1.2.3