authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-11 19:08:30 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-11 19:08:30 -07:00
log730c604553d7b8d47111061221b9fc826b4823ec
tree9ae4097156342348c45e25b024978fa13eef2d42
parent52205ca7e4c322e29d40767553027f973830bfcf
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

URL: add isHostLocal()


1 files changed, 24 insertions(+), 0 deletions(-)

url.zig+24
......@@ -977,6 +977,30 @@ pub const URL = struct {
977977 pub fn searchParams(u: *const URL, allocator: std.mem.Allocator) !SearchParams {
978978 return .initFromString(allocator, u.query());
979979 }
980
981 pub fn isHostLocal(u: *const URL) bool {
982 switch (u.hostFancy()) {
983 .unset => {
984 return false;
985 },
986 .name => |nm| {
987 if (std.mem.eql(u8, nm, "localhost")) return true;
988 if (std.mem.endsWith(u8, nm, ".localhost")) return true;
989 if (std.mem.endsWith(u8, nm, ".test")) return true;
990 if (std.mem.endsWith(u8, nm, ".example")) return true;
991 if (std.mem.endsWith(u8, nm, ".invalid")) return true;
992 if (std.mem.endsWith(u8, nm, ".home.arpa")) return true;
993 if (std.mem.endsWith(u8, nm, ".local")) return true;
994 return false;
995 },
996 .ipv4 => {
997 return false; // TODO
998 },
999 .ipv6 => {
1000 return false; // TODO
1001 },
1002 }
1003 }
9801004};
9811005
9821006pub const SearchParams = struct {