Module liburi

A module for generating, parsing, encoding, and decoding uris.

Copyright © Erlware, LLC.

Authors: Scott Parish (srp@srparish.net).

Description

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.

Data Types

bin_string()

bin_string() = binary() | list()

qs()

qs() = proplists:proplist() | binary()

uri()

uri() = #uri{scheme = binary(), user_info = binary(), host = binary(), port = non_neg_integer() | undefined, path = binary(), q = proplists:proplist(), frag = binary(), raw = binary()}

Function Index

append_path/2Append a path to the existing path of the system.
frag/1Return the frag field of uri().
frag/2Set the frag field of uri().
from_http_1_1/3Populate a new #uri record by using Scheme and parsing HostPort string Uri
from_string/1Populate a new uri record by parsing the string Uri
host/1Return the host field of uri().
host/2Set the host field of uri().
new/7Return a uri record with the given fields.
path/1Return the path field of uri().
path/2Set the path field of uri().
port/1Return the port field of uri().
port/2Set the port field of uri().
q/1Return the query field of uri().
q/2Set the query field of uri().
query_foldl/3Fold over each element of a query.
query_to_proplist/1Convert 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/1Return Str with all reserved or uri-unsafe characters in quoted form.
quote/2Return Str with all reserved or uri-unsafe characters in quoted form.
raw/1Return the raw field of uri().
raw_query/1Return the raw_query field of uri().
raw_query/2Set the raw_query field of uri().
scheme/1Return the scheme field of uri().
scheme/2Set the scheme field of uri().
to_query/1Convert a dictionary or proplist to an iolist representing the query part of a uri.
to_query/2Return 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/1Return the string this uri represents.
unquote/1Return Str with all + replaced with space, and %NN replaced with the decoded byte.
user_info/1Return the user_info field of uri().
user_info/2Set the user_info field of uri().

Function Details

append_path/2

append_path(Uri::uri(), NewPath::binary()) -> uri()

Append a path to the existing path of the system

frag/1

frag(Uri::uri()) -> binary()

Return the frag field of uri().

frag/2

frag(Uri::uri(), NewFrag::binary()) -> uri()

Set the frag field of uri().

from_http_1_1/3

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/1

from_string(Uri0::bin_string()) -> uri()

Populate a new uri record by parsing the string Uri

host/1

host(Uri::uri()) -> binary()

Return the host field of uri().

host/2

host(Uri::uri(), NewHost::binary()) -> uri()

Set the host field of uri().

new/7

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/1

path(Uri::uri()) -> binary()

Return the path field of uri().

path/2

path(Uri::uri(), NewPath::binary()) -> uri()

Set the path field of uri().

port/1

port(Uri::uri()) -> integer()

Return the port field of uri().

port/2

port(Uri::uri(), NewPort::integer()) -> uri()

Set the port field of uri().

q/1

q(Uri::uri()) -> proplists:proplist()

Return the query field of uri().

q/2

q(Uri::uri(), Query::proplists:proplist()) -> uri()

Set the query field of uri().

query_foldl/3

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/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.

For example, "range=5-50&printable" would result in the following proplist entries:
KeyValue
"range""5-50"
"printable"null
The string needent have to be from a uri, this method is also useful for decoding the Post body of an HTTP form submission.

quote/1

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/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:
any
Quote any character that is reserved in any potential part.
userinfo
Quote for the userinfo part of a uri.
path
Quote for the path part of a uri.
segment
Quote for a path's segment. This is much like path, but will also quote the / character.
segment_param
Quote for path segment's parameters (a fairly obscure part of uris). This is like path but will also quote the characters / and ;.
query_ | q
Quote for query parts. 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.
frag
Quote for the fragment part of a uri

raw/1

raw(Uri::uri()) -> binary()

Return the raw field of uri().

raw_query/1

raw_query(Uri::uri()) -> binary()

Return the raw_query field of uri().

raw_query/2

raw_query(Uri::uri(), NewRawQuery::binary()) -> uri()

Set the raw_query field of uri().

scheme/1

scheme(Uri::uri()) -> binary()

Return the scheme field of uri().

scheme/2

scheme(Uri::uri(), NewScheme::binary()) -> uri()

Set the scheme field of uri().

to_query/1

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/2

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/1

to_string(Uri::uri()) -> binary()

Return the string this uri represents. (Same as the raw field)

unquote/1

unquote(Str::binary()) -> binary()

Return Str with all + replaced with space, and %NN replaced with the decoded byte.

user_info/1

user_info(Uri::uri()) -> binary()

Return the user_info field of uri().

user_info/2

user_info(Uri::uri(), NewUserInfo::binary()) -> uri()

Set the user_info field of uri().


Generated by EDoc