Module encoding::url
URLs: percent-encoding (RFC 3986), the application/x-www-form-urlencoded format (query strings and HTML form bodies, as the WHATWG URL standard's URLSearchParams defines it), and a structured URL type with parsing, serialization and relative-reference resolution (RFC 3986 §5).
Pure string code, no I/O: usable on hosted, bare-metal and wasm32 targets alike (std/http uses it on the server, std/wasm-side code can use it for client-side routing).
Structs
| UrlQueryPair | |
| QueryParams | An ordered multi-map of decoded key/value pairs — the parsed form of "a=1&b=two%20words&a=3" (a query string without its '?', or an application/x-www-form-urlencoded request body). Keys may repeat; get() returns the first. Lookups are case-sensitive, like URLSearchParams. |
| Url | A URL split into its RFC 3986 components: |
Functions
| url_encode | Percent-encodes every byte except the unreserved set (A-Z a-z 0-9 - _ . ~) — this matches the "component" flavor used for query-string keys/values and path segments (JavaScript's encodeURIComponent, not encodeURI). Space becomes "%20" (not "+" — that's an application/x-www-form-urlencoded convention some callers layer on top, not part of RFC 3986 itself; see form_encode below). |
| url_decode | Reverses url_encode: "%XX" becomes the raw byte 0xXX, "+" is left as a literal '+' (not decoded to space — see url_encode's note; use form_decode for form data). On a malformed "%" escape (not followed by two hex digits), '*ok' (if non-NULL) is set to 0 and decoding stops at that point; otherwise '*ok' is set to 1. |
| url_encode_path | Like url_encode, but keeps the characters a URL path may hold as-is: '/', and RFC 3986's sub-delims and ':' '@' (so "/a b/c:d" becomes "/a%20b/c:d"). '%' itself is always escaped, so this is not idempotent — encode raw paths, not already-encoded ones. |
| form_encode | application/x-www-form-urlencoded: url_encode, except that space becomes '+' and '*' stays as-is (the WHATWG urlencoded serializer's byte set). |
| form_decode | Reverses form_encode: '+' becomes a space, "%XX" a byte. Unlike url_decode, a malformed '%' escape is kept literally (browsers do the same) and never fails. |
| url_remove_dot_segments | RFC 3986 §5.2.4: "/a/b/../c/./d" -> "/a/c/d". |