Copyright © Erlware, LLC.
Authors: Scott Parish (srp@srparish.net).
A module for generating, parsing, encoding, and decoding uris.
At the moment this module isn't very sympathetic to non-http uri's, but that could/should change in the future.bin_string() = binary() | list()
qs() = proplists:proplist() | binary()
uri() = #uri{scheme = binary(), user_info = binary(), host = binary(), port = non_neg_integer() | undefined, path = binary(), q = proplists:proplist(), frag = binary(), raw = binary()}
append_path/2 | Append a path to the existing path of the system. |
frag/1 | Return the frag field of uri() . |
frag/2 | Set the frag field of uri() . |
from_http_1_1/3 | Populate a new #uri record by using Scheme and parsing HostPort string Uri |
from_string/1 | Populate a new uri record by parsing the string Uri |
host/1 | Return the host field of uri() . |
host/2 | Set the host field of uri() . |
new/7 | Return a uri record with the given fields. |
path/1 | Return the path field of uri() . |
path/2 | Set the path field of uri() . |
port/1 | Return the port field of uri() . |
port/2 | Set the port field of uri() . |
q/1 | Return the query field of uri() . |
q/2 | Set the query field of uri() . |
query_foldl/3 | Fold over each element of a query. |
query_to_proplist/1 | Convert the string or the raw_query portion of uri() into a proplists:proplist() , where the keys
are binaries, the values are binaries, and for valueless keys, the atom null is used as the value. |
quote/1 | Return Str with all reserved or uri-unsafe characters in quoted form. |
quote/2 | Return Str with all reserved or uri-unsafe characters in quoted form. |
raw/1 | Return the raw field of uri() . |
raw_query/1 | Return the raw_query field of uri() . |
raw_query/2 | Set the raw_query field of uri() . |
scheme/1 | Return the scheme field of uri() . |
scheme/2 | Set the scheme field of uri() . |
to_query/1 | Convert a dictionary or proplist to an iolist representing the query part of a uri. |
to_query/2 | Return an binary representing the query part of a uri by folding over Ds by calling the provided FoldF ,
which should take three arguments: a function, an initial accumulator value, and the data structure to fold over. |
to_string/1 | Return the string this uri represents. |
unquote/1 | Return Str with all + replaced with space, and %NN replaced with the decoded byte. |
user_info/1 | Return the user_info field of uri() . |
user_info/2 | Set the user_info field of uri() . |
Append a path to the existing path of the system
frag(Uri::uri()) -> binary()
Return the frag field of uri()
.
Set the frag field of uri()
.
from_http_1_1(Scheme::binary(), HostPort::binary(), Uri::binary()) -> uri()
Populate a new #uri record by using Scheme
and parsing HostPort
string Uri
from_string(Uri0::bin_string()) -> uri()
Populate a new uri record by parsing the string Uri
host(Uri::uri()) -> binary()
Return the host field of uri()
.
Set the host field of uri()
.
new(Scheme::binary(), UserInfo::binary(), Host::binary(), Port::non_neg_integer() | undefined, Path::binary(), Query::qs(), Frag::binary()) -> uri()
Return a uri record with the given fields. Use ""
for any field that isn't used.
You probably want raw/7
unless you've parsed a uri yourself.
path(Uri::uri()) -> binary()
Return the path field of uri()
.
Set the path field of uri()
.
port(Uri::uri()) -> integer()
Return the port field of uri()
.
Set the port field of uri()
.
q(Uri::uri()) -> proplists:proplist()
Return the query field of uri()
.
q(Uri::uri(), Query::proplists:proplist()) -> uri()
Set the query field of uri()
.
query_foldl(F::fun((proplists:property(), Acc::term()) -> term()), Acc::term(), Uri::qs() | uri()) -> Acc::term()
Fold over each element of a query. For instance with the query "range=5-50&printable"
, F
will be called as
F("range", "5-50", Acc)
and F("printable", null, Acc)
.
Both Key
and Value
are already unquoted when F
is called. @see query_to_dict/1
query_to_proplist(Query::binary()) -> proplists:proplist()
Convert the string or the raw_query
portion of uri()
into a proplists:proplist()
, where the keys
are binaries, the values are binaries, and for valueless keys, the atom null
is used as the value.
"range=5-50&printable"
would result in the following proplist entries:
Key | Value |
---|---|
"range" | "5-50" |
"printable" | null |
Post
body of an HTTP form submission.
quote(Str::binary()) -> binary()
Return Str
with all reserved or uri-unsafe characters in quoted form. For instance "A Space"
becomes "A%20Space"
. This is the same as calling quote(Str, any)
.
See also: quote/2.
quote(Str::binary(), Part::atom()) -> binary()
Return Str
with all reserved or uri-unsafe characters in quoted form. Since rfc-2396 has different
reserved characters for different parts of the uri, you can specify Part
to obtain a minimally quoted uri for that Part
.
Part
can be one of the following values:
path
, but will also quote the /
character.path
but will also quote the characters /
and ;
.query
is an erlang keyword so you can either use q
or query_
to specify this part. This
will quote characters such as &
and =
, so it needs to be called on the individual key/value parts of a query. See
to_query/1
and to_query/1
.raw(Uri::uri()) -> binary()
Return the raw field of uri()
.
raw_query(Uri::uri()) -> binary()
Return the raw_query field of uri()
.
Set the raw_query field of uri()
.
scheme(Uri::uri()) -> binary()
Return the scheme field of uri()
.
Set the scheme field of uri()
.
to_query(List::proplist:proplist()) -> binary()
Convert a dictionary or proplist to an iolist representing the query part of a uri. Keys and values can be binaries, lists, atoms, integers or floats, and will be automatically converted to a string and quoted.
to_query(FoldF::function(), Ds::binary() | proplist:proplist()) -> binary()
Return an binary representing the query part of a uri by folding over Ds
by calling the provided FoldF
,
which should take three arguments: a function, an initial accumulator value, and the data structure to fold over.
See also: to_query/1.
to_string(Uri::uri()) -> binary()
Return the string this uri represents. (Same as the raw
field)
unquote(Str::binary()) -> binary()
Return Str
with all +
replaced with space, and %NN
replaced with the decoded byte.
user_info(Uri::uri()) -> binary()
Return the user_info field of uri()
.
Set the user_info field of uri()
.
Generated by EDoc