Fetch.URL (Fetch v0.1.0)

View Source

Turns a URL string into the pieces an HTTP/1.1 request needs.

URI syntax is tokenized by URI.new/1 from the standard library. This module adds the HTTP-specific part:

  • only http and https schemes
  • a host is required
  • default ports: 80 for http, 443 for https
  • the request target (/path?query) — the fragment is never sent, it only exists on the client side
  • the authority for the host header — the port is omitted when it is the default one, IPv6 literals are put back into brackets
  • user:pass@host is rejected: silently dropping credentials or sending them is a decision we do not make implicitly

Summary

Functions

Validates a request path such as /users?page=2 for a connection that already knows its origin. The fragment is dropped.

Types

t()

@type t() :: %{
  scheme: :http | :https,
  host: String.t(),
  port: :inet.port_number(),
  authority: String.t(),
  target: String.t()
}

Functions

parse(url)

@spec parse(String.t()) :: {:ok, t()} | {:error, {:url, term()}}

parse_target(path)

@spec parse_target(String.t()) :: {:ok, String.t()} | {:error, {:url, term()}}

Validates a request path such as /users?page=2 for a connection that already knows its origin. The fragment is dropped.