| ... | ... | @@ -960,6 +960,18 @@ pub const URL = struct { |
| 960 | 960 | .ipv6 => .{ .ipv6 = parseIPv6(u.hostname[1 .. u.hostname.len - 1]) catch unreachable }, |
| 961 | 961 | }; |
| 962 | 962 | } |
| 963 | |
| 964 | pub fn portFancy(u: *const URL) ?u16 { |
| 965 | if (u.port.len > 0) return std.fmt.parseUnsigned(u16, u.port, 10) catch unreachable; |
| 966 | const s = u.scheme(); |
| 967 | if (std.mem.eql(u8, s, "ftp")) return 21; |
| 968 | if (std.mem.eql(u8, s, "file")) return null; |
| 969 | if (std.mem.eql(u8, s, "http")) return 80; |
| 970 | if (std.mem.eql(u8, s, "https")) return 443; |
| 971 | if (std.mem.eql(u8, s, "ws")) return 80; |
| 972 | if (std.mem.eql(u8, s, "wss")) return 443; |
| 973 | return null; |
| 974 | } |
| 963 | 975 | }; |
| 964 | 976 | |
| 965 | 977 | /// https://url.spec.whatwg.org/#special-scheme |