From 730c604553d7b8d47111061221b9fc826b4823ec Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 11 Jun 2026 19:08:30 -0700 Subject: [PATCH] URL: add isHostLocal() --- url.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/url.zig b/url.zig index 9cc1cc879807e9fa9e1a9a0e937c9d6b00a40bd9..0be343b619aaf0e5b4fcdea0998fb0ebc6496a87 100644 --- a/url.zig +++ b/url.zig @@ -977,6 +977,30 @@ pub const URL = struct { pub fn searchParams(u: *const URL, allocator: std.mem.Allocator) !SearchParams { return .initFromString(allocator, u.query()); } + + pub fn isHostLocal(u: *const URL) bool { + switch (u.hostFancy()) { + .unset => { + return false; + }, + .name => |nm| { + if (std.mem.eql(u8, nm, "localhost")) return true; + if (std.mem.endsWith(u8, nm, ".localhost")) return true; + if (std.mem.endsWith(u8, nm, ".test")) return true; + if (std.mem.endsWith(u8, nm, ".example")) return true; + if (std.mem.endsWith(u8, nm, ".invalid")) return true; + if (std.mem.endsWith(u8, nm, ".home.arpa")) return true; + if (std.mem.endsWith(u8, nm, ".local")) return true; + return false; + }, + .ipv4 => { + return false; // TODO + }, + .ipv6 => { + return false; // TODO + }, + } + } }; pub const SearchParams = struct { -- 2.54.0