url/location host getter

This commit is contained in:
Karl Seguin
2025-11-01 20:25:41 +08:00
parent d397d75aca
commit 8b3f36c1f8
3 changed files with 11 additions and 1 deletions

View File

@@ -233,7 +233,7 @@ fn getUserInfo(raw: [:0]const u8) ?[]const u8 {
return null;
}
fn getHost(raw: [:0]const u8) []const u8 {
pub fn getHost(raw: [:0]const u8) []const u8 {
const scheme_end = std.mem.indexOf(u8, raw, "://") orelse return "";
var authority_start = scheme_end + 3;

View File

@@ -26,6 +26,10 @@ pub fn getHostname(self: *const Location) []const u8 {
return self._url.getHostname();
}
pub fn getHost(self: *const Location) []const u8 {
return self._url.getHost();
}
pub fn getPort(self: *const Location) []const u8 {
return self._url.getPort();
}
@@ -61,6 +65,7 @@ pub const JsApi = struct {
pub const hash = bridge.accessor(Location.getHash, null, .{});
pub const pathname = bridge.accessor(Location.getPathname, null, .{});
pub const hostname = bridge.accessor(Location.getHostname, null, .{});
pub const host = bridge.accessor(URL.getHost, null, .{});
pub const port = bridge.accessor(Location.getPort, null, .{});
pub const origin = bridge.accessor(Location.getOrigin, null, .{});
pub const protocol = bridge.accessor(Location.getProtocol, null, .{});

View File

@@ -62,6 +62,10 @@ pub fn getHostname(self: *const URL) []const u8 {
return U.getHostname(self._raw);
}
pub fn getHost(self: *const URL) []const u8 {
return U.getHost(self._raw);
}
pub fn getPort(self: *const URL) []const u8 {
return U.getPort(self._raw);
}
@@ -180,6 +184,7 @@ pub const JsApi = struct {
pub const username = bridge.accessor(URL.getUsername, null, .{});
pub const password = bridge.accessor(URL.getPassword, null, .{});
pub const hostname = bridge.accessor(URL.getHostname, null, .{});
pub const host = bridge.accessor(URL.getHost, null, .{});
pub const port = bridge.accessor(URL.getPort, null, .{});
pub const origin = bridge.accessor(URL.getOrigin, null, .{});
pub const protocol = bridge.accessor(URL.getProtocol, null, .{});