URL
#struct URLA parsed web address.
| Name | Type | Description |
|---|---|---|
scheme | str = "" | The scheme, such as https. |
userinfo | str = "" | The user name and password before the @, still encoded. |
host | str = "" | The host name or numeric address. |
port | int = 0 | The port, or zero when none was given. |
path | str = "" | The path, still encoded. |
raw_query | str = "" | The query after the ?, still encoded. |
fragment | str = "" | The part after the #. |
import encoding.url
import encoding.query
func main throw:
mut u := try url.Parse(
"https://user%20a:pw@shop.example.co.uk:8443/books/%D8%B3%D9%84%D8%A7%D9%85?page=2&sort=new#top"
)
println u.scheme, u.host, u.port, u.path, u.raw_query, u.fragment
println url.Hostname(u), url.HostPort(u), url.IsIP(u)
println url.Labels(u), url.PublicSuffix(u), url.Domain(u), url.Subdomain(u)
println try url.DecodedPath(u), try url.DecodedUserinfo(u)
println try url.ParamNames(u), query.Size(try url.Query(u))
try url.SetParam(u, "page", "3")
println try url.RemoveParam(u, "sort"), url.String(u)
mut keep := Vector {} as Vector<str>
keep.Push("page")
try url.KeepParams(u, keep)
mut q := query.NewQueryMap()
query.Add(q, "q", "hello world")
url.SetQuery(u, q)
println url.String(u)
url.ClearQuery(u)
println url.String(u)
println url.String(try url.Join(u, "../img/a.png")), url.EncodePathSegment("a b/c")
println url.IsIP(try url.Parse("http://127.0.0.1/"))
try:
_ := url.Parse("https://shop.example.com:80a/")
catch e:
println e.KindName(), e.ToStr()
end
endhttps shop.example.co.uk 8443 /books/%D8%B3%D9%84%D8%A7%D9%85 page=2&sort=new top shop.example.co.uk shop.example.co.uk:8443 false ["shop", "example", "co", "uk"] co.uk example.co.uk shop /books/سلام user a:pw ["page", "sort"] 2 true https://user%20a:pw@shop.example.co.uk:8443/books/%D8%B3%D9%84%D8%A7%D9%85?page=3#top https://user%20a:pw@shop.example.co.uk:8443/books/%D8%B3%D9%84%D8%A7%D9%85?q=hello+world#top https://user%20a:pw@shop.example.co.uk:8443/books/%D8%B3%D9%84%D8%A7%D9%85#top https://user%20a:pw@shop.example.co.uk:8443/img/a.png a%20b%2Fc true syntax error url: invalid character 'a' in port (line 1, column 28)