Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

Uri

2 types5 functions

The URI pieces Http needs: query strings, percent-encoding and path segments. Query parameters are name/value records, since Bert has no tuples.

At a glance

  • QueryParam

    One name=value pair of a query string, both percent-decoded.

  • Result

    Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

  • parseQuery

    The &-separated name=value pairs of a query, each side percent-decoded with + read as a space.

  • queryToString

    The pairs as a query, each side percent-encoded, with + encoded too so that parseQuery does not read it back as a space.

  • percentEncode

    Each UTF-8 byte outside the unreserved set as %XX, in uppercase hex.

  • percentDecode

    Each %XX as the byte it encodes, and + kept as it is.

  • pathSegments

    The non-empty segments of a path, with each . dropped and each .. dropping the segment before it, as RFC 3986 resolves dot-segments.

Types

QueryParam

QueryParam = { name: String, value: String }

One name=value pair of a query string, both percent-decoded.

Result

Result(a, e) = [Ok(a) | Err(e)]

Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

Functions

parseQuery

(String) -> Result(List(QueryParam), [InvalidEncoding | e])pure

The &-separated name=value pairs of a query, each side percent-decoded with + read as a space. A pair with no = has the empty value; an empty query, or an empty piece between two &, holds no pair. Any encoding that does not decode to UTF-8 is an Err, and so are raw bytes that are not UTF-8.

queryToString

(List(QueryParam)) -> Stringpure

The pairs as a query, each side percent-encoded, with + encoded too so that parseQuery does not read it back as a space.

percentEncode

(String) -> Stringpure

Each UTF-8 byte outside the unreserved set as %XX, in uppercase hex. ASCII letters, digits and ! $ ' ( ) * + - . _ ~ are kept as they are.

percentDecode

(String) -> Result(String, [InvalidEncoding | e])pure

Each %XX as the byte it encodes, and + kept as it is. The bytes must form UTF-8, and a % not followed by two hex digits is an Err too.

pathSegments

(String) -> List(String)pure

The non-empty segments of a path, with each . dropped and each .. dropping the segment before it, as RFC 3986 resolves dot-segments. A .. with nothing before it is dropped.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.