This module contains functions for parsing and handling URIs (RFC 3986) and form-urlencoded query strings (RFC 1866).
A URI is an identifier consisting of a sequence of characters matching the syntax rule named URI in RFC 3986.
The generic URI syntax consists of a hierarchical sequence of components referred to as the scheme, authority, path, query, and fragment:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) authority = [ userinfo "@" ] host [ ":" port ] userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
The interpretation of a URI depends only on the characters used and not on how those characters are represented in a network protocol.
The functions implemented by this module covers the following use cases:
There are four different encodings present during the handling of URIs:
Unless otherwise specified the return value type and encoding are the same as the input
type and encoding. That is, binary input returns binary output, list input returns a list
output but mixed input returns list output. Input and output encodings are the same except
for
All of the functions but
URI map holding the main components of a URI.
List of unicode codepoints, UTF-8 encoded binary, or a mix of the two, representing an RFC 3986 compliant URI (percent-encoded form). A URI is a sequence of characters from a very limited set: the letters of the basic Latin alphabet, digits, and a few special characters.
Composes a form-urlencoded
Example:
1> uri_string:compose_query([{"foo bar","1"},{"city","örebro"}]).
Same as
Example:
1> uri_string:compose_query([{"foo bar","1"},{"city","örebro"}], 2> [{separator, semicolon}]). "foo+bar=1;city=%C3%B6rebro"
Dissects an urlencoded
Example:
1> uri_string:dissect_query("foo+bar=1;city=%C3%B6rebro"). [{"foo bar","1"},{"city","örebro"}]
Returns a
If parsing fails, an error tuple is returned.
Example:
1> uri_string:parse("foo://user@example.com:8042/over/there?name=ferret#nose"). #{fragment => "nose",host => "example.com", path => "/over/there",port => 8042,query => "name=ferret", scheme => foo,userinfo => "user"}
Returns an RFC 3986 compliant
If the
Example:
1> URIMap = #{fragment => "nose", host => "example.com", path => "/over/there", port => 8042, query => "name=ferret", scheme => "foo", userinfo => "user"}. #{fragment => "top",host => "example.com", path => "/over/there",port => 8042,query => "?name=ferret", scheme => foo,userinfo => "user"} 2> uri_string:recompose(URIMap). "foo://example.com:8042/over/there?name=ferret#nose"
Transcodes an RFC 3986 compliant
If an argument is invalid, an error tuple is returned.
Example:
1> >,]]> 2> [{in_encoding, utf32},{out_encoding, utf8}]). >]]>