View Source z_url (zotonic_stdlib v1.23.1)

Misc utility URL functions for zotonic

Summary

Functions

Given a relative URL and a base URL, calculate the absolute URL.

Decode a "data:" url to its parts. If the charset is not defined in the data then it is returned as "US-ASCII". The mime type defaults to "text/plain".

Find the definitive location of an url, removing url shorteners in the process. Identify as Curl to prevent url shorteners returning HTML pages.

Percent encoding/decoding as defined by RFC 3986 (http://tools.ietf.org/html/rfc3986).

Naive function to remove the protocol from an Url

Functions

abs_link(Url, BaseUrl)

-spec abs_link(Url, BaseUrl) -> AbsUrl
                  when Url :: string() | binary(), BaseUrl :: string() | binary(), AbsUrl :: binary().

Given a relative URL and a base URL, calculate the absolute URL.

decode_data_url(DataUrl)

-spec decode_data_url(DataUrl) -> {ok, Mime, Charset, Data} | {error, Reason}
                         when
                             DataUrl :: binary(),
                             Mime :: binary(),
                             Charset :: binary(),
                             Data :: binary(),
                             Reason :: unknown_encoding | nodata.

Decode a "data:" url to its parts. If the charset is not defined in the data then it is returned as "US-ASCII". The mime type defaults to "text/plain".

encode_data_url(Mime, Charset, Data)

-spec encode_data_url(Mime, Charset, Data) -> Encoded
                         when
                             Mime :: binary(),
                             Charset :: binary() | undefined,
                             Data :: binary(),
                             Encoded :: binary().

hex_decode(Data)

-spec hex_decode(binary()) -> binary().

hex_encode(Data)

-spec hex_encode(iodata()) -> binary().

hex_encode_lc(Data)

-spec hex_encode_lc(iodata()) -> binary().

location(Url)

Find the definitive location of an url, removing url shorteners in the process. Identify as Curl to prevent url shorteners returning HTML pages.

percent_encode(Chars)

-spec percent_encode(iodata()) -> binary().

Percent encoding/decoding as defined by RFC 3986 (http://tools.ietf.org/html/rfc3986).

percent_encode(_, Acc)

remove_protocol(Rest)

-spec remove_protocol(string()) -> string();
                     (binary()) -> binary().

Naive function to remove the protocol from an Url

split_base_host(Base)

-spec split_base_host(string() | binary()) -> {binary(), binary()}.

url_decode(Encoded)

-spec url_decode(Encoded) -> Data when Encoded :: iodata(), Data :: binary().

url_encode(Value)

-spec url_encode(Value) -> Encoded
                    when
                        Value :: string() | atom() | float() | integer() | binary() | iodata(),
                        Encoded :: binary().

url_path_encode(L)

-spec url_path_encode(iodata()) -> binary().

url_reserved_char(_)

url_unreserved_char(Ch)

url_valid_char(Char)

-spec url_valid_char(Char) -> boolean() when Char :: non_neg_integer().