Runlight.Url (runlight v0.1.0)

Copy Markdown View Source

A URL parsed as the WHATWG URL standard parses one, as new URL() does in JavaScript, so every port reads a request's address the same way.

Documented for its type; its functions are internal and can change in any release.

Summary

Functions

Percent-encodes C0 controls, DEL, bytes past ASCII, and the extra characters; escapes already there stay.

url.host: the hostname, with the port when there is one.

url.href, which toString() gives too.

new URL(input, base), raising ArgumentError as the constructor throws.

url.origin.

new URL(input, base), or nil where it throws.

Assigning url.pathname.

Assigning url.search: one leading ? is dropped and the rest percent-encoded; empty removes it.

url.searchParams.

The URL with these parameters as its query, as changing url.searchParams does.

Types

t()

@type t() :: %Runlight.Url{
  authority: term(),
  hash: term(),
  hostname: term(),
  password: term(),
  pathname: term(),
  port: term(),
  protocol: term(),
  search: term(),
  username: term()
}

Functions

encode(text, extra)

@spec encode(String.t(), charlist()) :: String.t()

Percent-encodes C0 controls, DEL, bytes past ASCII, and the extra characters; escapes already there stay.

host(url)

@spec host(t()) :: String.t()

url.host: the hostname, with the port when there is one.

href(url)

@spec href(t()) :: String.t()

url.href, which toString() gives too.

new(input, base \\ nil)

@spec new(String.t(), String.t() | t() | nil) :: t()

new URL(input, base), raising ArgumentError as the constructor throws.

origin(url)

@spec origin(t()) :: String.t()

url.origin.

parse(input, base \\ nil)

@spec parse(String.t() | nil, String.t() | t() | nil) :: t() | nil

new URL(input, base), or nil where it throws.

put_pathname(url, path)

@spec put_pathname(t(), String.t()) :: t()

Assigning url.pathname.

put_search(url, search)

@spec put_search(t(), String.t()) :: t()

Assigning url.search: one leading ? is dropped and the rest percent-encoded; empty removes it.

search_params(url)

@spec search_params(t()) :: Runlight.SearchParams.t()

url.searchParams.

with_params(url, params)

@spec with_params(t(), Runlight.SearchParams.t()) :: t()

The URL with these parameters as its query, as changing url.searchParams does.