Module rabbit_http_util

Utilities for parsing and quoting.

Copyright © 2007 Mochi Media, Inc.

Authors: Bob Ippolito (bob@mochimedia.com).

Description

Utilities for parsing and quoting.

Data Types

encoding()

encoding() = string()

media_type()

media_type() = string()

qvalue()

qvalue() = {media_type() | encoding(), float()}

Function Index

cmd/1os:cmd(cmd_string(Argv)).
cmd_port/2open_port({spawn, mochiweb_util:cmd_string(Argv)}, Options).
cmd_status/1Accumulate the output and exit status from the given application, will be spawned with cmd_port/2.
cmd_status/2Accumulate the output and exit status from the given application, will be spawned with cmd_port/2.
cmd_string/1Create a shell quoted command string from a list of arguments.
join/2Join a list of strings or binaries together with the given separator string or char or binary.
make_io/1
parse_header/1 Parse a Content-Type like header, return the main Content-Type and a property list of options.
parse_qs/1Parse a query string or application/x-www-form-urlencoded.
parse_qvalues/1Parses a list (given as a string) of elements with Q values associated to them.
partition/2Inspired by Python 2.5's str.partition: partition("foo/bar", "/") = {"foo", "/", "bar"}, partition("foo", "/") = {"foo", "", ""}.
path_split/1Split a path starting from the left, as in URL traversal.
pick_accepted_encodings/3Determines which encodings specified in the given Q values list are valid according to a list of supported encodings and a default encoding.
quote_plus/1URL safe encoding of the given term.
record_to_proplist/2calls record_to_proplist/3 with a default TypeKey of '__record'.
record_to_proplist/3Return a proplist of the given Record with each field in the Fields list set as a key with the corresponding value in the Record.
safe_relative_path/1Return the reduced version of a relative path or undefined if it is not safe.
shell_quote/1Quote a string according to UNIX shell quoting rules, returns a string surrounded by double quotes.
unquote/1Unquote a URL encoded string.
urlencode/1URL encode the property list.
urlsplit/1Return a 5-tuple, does not expand % escapes.
urlsplit_path/1Return a 3-tuple, does not expand % escapes.
urlunsplit/1Assemble a URL from the 5-tuple.
urlunsplit_path/1Assemble a URL path from the 3-tuple.

Function Details

cmd/1

cmd(Argv::[string()]) -> string()

os:cmd(cmd_string(Argv)).

cmd_port/2

cmd_port(Argv::[string()], Options) -> port()

open_port({spawn, mochiweb_util:cmd_string(Argv)}, Options).

cmd_status/1

cmd_status(Argv::[string()]) -> {ExitStatus::integer(), Stdout::binary()}

Accumulate the output and exit status from the given application, will be spawned with cmd_port/2.

cmd_status/2

cmd_status(Argv::[string()], Options::[atom()]) -> {ExitStatus::integer(), Stdout::binary()}

Accumulate the output and exit status from the given application, will be spawned with cmd_port/2.

cmd_string/1

cmd_string(Argv::[string()]) -> string()

Create a shell quoted command string from a list of arguments.

join/2

join(Strings::[iolist()], Separator::iolist()) -> iolist()

Join a list of strings or binaries together with the given separator string or char or binary. The output is flattened, but may be an iolist() instead of a string() if any of the inputs are binary().

make_io/1

make_io(Atom) -> any()

parse_header/1

parse_header(String::string()) -> {Type, [{K, V}]}

Parse a Content-Type like header, return the main Content-Type and a property list of options.

parse_qs/1

parse_qs(Binary::string() | binary()) -> [{Key, Value}]

Parse a query string or application/x-www-form-urlencoded.

parse_qvalues/1

parse_qvalues(QValuesStr::string()) -> [qvalue()] | invalid_qvalue_string

Parses a list (given as a string) of elements with Q values associated to them. Elements are separated by commas and each element is separated from its Q value by a semicolon. Q values are optional but when missing the value of an element is considered as 1.0. A Q value is always in the range [0.0, 1.0]. A Q value list is used for example as the value of the HTTP "Accept" and "Accept-Encoding" headers.

Q values are described in section 2.9 of the RFC 2616 (HTTP 1.1).

Example:

parse_qvalues("gzip; q=0.5, deflate, identity;q=0.0") -> [{"gzip", 0.5}, {"deflate", 1.0}, {"identity", 0.0}]

partition/2

partition(String, Sep) -> {String, [], []} | {Prefix, Sep, Postfix}

Inspired by Python 2.5's str.partition: partition("foo/bar", "/") = {"foo", "/", "bar"}, partition("foo", "/") = {"foo", "", ""}.

path_split/1

path_split(S::string()) -> {Part, Rest}

Split a path starting from the left, as in URL traversal. path_split("foo/bar") = {"foo", "bar"}, path_split("/foo/bar") = {"", "foo/bar"}.

pick_accepted_encodings/3

pick_accepted_encodings(AcceptedEncs::[qvalue()], SupportedEncs::[encoding()], DefaultEnc::encoding()) -> [encoding()]

Determines which encodings specified in the given Q values list are valid according to a list of supported encodings and a default encoding.

The returned list of encodings is sorted, descendingly, according to the Q values of the given list. The last element of this list is the given default encoding unless this encoding is explicitly or implicitly marked with a Q value of 0.0 in the given Q values list. Note: encodings with the same Q value are kept in the same order as found in the input Q values list.

This encoding picking process is described in section 14.3 of the RFC 2616 (HTTP 1.1).

Example:

pick_accepted_encodings( [{"gzip", 0.5}, {"deflate", 1.0}], ["gzip", "identity"], "identity" ) -> ["gzip", "identity"]

quote_plus/1

quote_plus(Atom::atom() | integer() | float() | string() | binary()) -> string()

URL safe encoding of the given term.

record_to_proplist/2

record_to_proplist(Record, Fields) -> proplist()

calls record_to_proplist/3 with a default TypeKey of '__record'

record_to_proplist/3

record_to_proplist(Record, Fields, TypeKey) -> proplist()

Return a proplist of the given Record with each field in the Fields list set as a key with the corresponding value in the Record. TypeKey is the key that is used to store the record type Fields should be obtained by calling record_info(fields, record_type) where record_type is the record type of Record

safe_relative_path/1

safe_relative_path(P::string()) -> string() | undefined

Return the reduced version of a relative path or undefined if it is not safe. safe relative paths can be joined with an absolute path and will result in a subdirectory of the absolute path. Safe paths never contain a backslash character.

shell_quote/1

shell_quote(L::string()) -> string()

Quote a string according to UNIX shell quoting rules, returns a string surrounded by double quotes.

unquote/1

unquote(Binary::string() | binary()) -> string()

Unquote a URL encoded string.

urlencode/1

urlencode(Props::[{Key, Value}]) -> string()

URL encode the property list.

urlsplit/1

urlsplit(Url) -> {Scheme, Netloc, Path, Query, Fragment}

Return a 5-tuple, does not expand % escapes. Only supports HTTP style URLs.

urlsplit_path/1

urlsplit_path(Path::Url) -> {Path, Query, Fragment}

Return a 3-tuple, does not expand % escapes. Only supports HTTP style paths.

urlunsplit/1

urlunsplit(X1::{Scheme, Netloc, Path, Query, Fragment}) -> string()

Assemble a URL from the 5-tuple. Path must be absolute.

urlunsplit_path/1

urlunsplit_path(X1::{Path, Query, Fragment}) -> string()

Assemble a URL path from the 3-tuple.


Generated by EDoc