packages

http::uri

On this page

URIs (RFC 3986): parsing, normalization, reference resolution, percent-encoding and application/x-www-form-urlencoded.

Structs

UriSource

pub struct Uri

A URI reference. scheme is "" and host is none for a relative reference (/a?b). host keeps an IPv6 literal without its brackets. Components keep their percent-encoding.

  • pub scheme: str = ""§

    Source
  • pub userinfo: str | none = none§

    Source
  • pub host: str | none = none§

    Source
  • pub port: u16 | none = none§

    Source
  • pub path: str = ""§

    Source
  • pub query: str | none = none§

    Source
  • pub fragment: str | none = none§

    Source
  • pub fn parse(s: str) throws (HttpError) -> Uri§

    Source

    Parse a URI reference strictly: every character must be allowed in its component and every % must start a %XX escape.

  • pub fn is_absolute(self) -> bool§

    Source
  • pub fn authority(self) -> str§

    Source

    host[:port] as a Host header / :authority value (no userinfo); "" without a host.

  • pub fn port_or_default(self) -> u16 | none§

    Source

    The port, or the scheme's default (80 / 443); none if neither.

  • pub fn path_and_query(self) -> str§

    Source

    Path and query as a request target (/ for an empty path).

  • pub fn query_pairs(self) -> List<(str, str)>§

    Source

    The query as (name, value) pairs (form-decoded).

  • pub fn normalize(self) -> Uri§

    Source

    The syntax-based normalization of RFC 3986 plus the scheme-based one for http / https: lowercase scheme and host, uppercase escapes, unreserved characters decoded, dot segments removed, a default port dropped, an empty path made /.

  • pub fn resolve(self, reference: Uri) -> Uri§

    Source

    Resolve reference against this base URI.

  • pub fn join(self, s: str) throws (HttpError) -> Uri§

    Source

    Resolve the reference text s against this URI.

Trait implementations 1
  • impl Display for Uri

Functions

remove_dot_segmentsSource

pub fn remove_dot_segments(path: str) -> str

path with its . and .. segments resolved.

percent_encodeSource

pub fn percent_encode(s: str, keep: str = "") -> str

s with every byte that is not unreserved and not in keep as a %XX escape (UTF-8 bytes each escaped).

percent_decode_bytesSource

pub fn percent_decode_bytes(s: str) throws (HttpError) -> List<u8>

The bytes s encodes; throws on a malformed escape.

percent_decodeSource

pub fn percent_decode(s: str) throws (HttpError) -> str

The text s encodes; throws on a malformed escape or invalid UTF-8.

form_encodeSource

pub fn form_encode(pairs: List<(str, str)>) -> str

application/x-www-form-urlencoded (WHATWG URL): a=1&b=x+y.

form_decodeSource

pub fn form_decode(s: str) -> List<(str, str)>

Decode a form body / query leniently as browsers do: empty pieces skipped, + is a space, a malformed escape stays as written, invalid UTF-8 becomes U+FFFD.