This module contains functions for parsing and handling URIs
(
A URI is an identifier consisting of a sequence of characters matching the syntax
rule named URI in
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 cover the following use cases:
There are four different encodings present during the handling of URIs:
Functions with
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.
In case of lists there is only percent-encoding. In binaries, however, both binary encoding
and percent-encoding shall be considered.
Error tuple indicating the type of error. Possible values of the second component:
The third component is a term providing additional information about the cause of the error.
Map holding the main components of a URI.
List of unicode codepoints, a UTF-8 encoded binary, or a mix of the two,
representing an
Transforms
This function implements case normalization, percent-encoding normalization, path segment normalization and scheme based normalization for HTTP(S) with basic support for FTP, SSH, SFTP and TFTP.
Example:
1> uri_string:normalize("/a/b/c/./../../g"). "/a/g" 2> >).]]> >]]> 3> uri_string:normalize("http://localhost:80"). "https://localhost/"
Parses an
See also the opposite operation
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"} 2> >).]]> <<"example.com">>,path => <<"/over/there">>, port => 8042,query => <<"name=ferret">>,scheme => <<"foo">>, userinfo => <<"user">>}]]>
Creates an
See also the opposite operation
Example:
1> URIMap = #{fragment => "nose", host => "example.com", path => "/over/there", 1> 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
Example:
1> >,]]> 1> [{in_encoding, utf32},{out_encoding, utf8}]). >]]> 2> uri_string:transcode("foo%F6bar", [{in_encoding, latin1}, 2> {out_encoding, utf8}]). "foo%C3%B6bar"