Module uri
net only.Expand description
First-class URI support for rama.
This module hosts the rama-native URI type. It works for any RFC 3986
URI — http(s), ws(s), ftp, mailto:, urn:, file:, custom schemes — not
just HTTP. HTTP-specific shapes (e.g. asterisk-form * from RFC 9112
§3.2.4) are supported but called out as such.
Graceful by default, lossless on parse (no silent normalization),
preserves fragments, and lets you cheaply mutate components without
the into_parts → from_parts dance.
§HTTP request-target forms (RFC 9112 §3.2)
All four shapes are reachable, but not through a single auto-detecting
entry point — the grammar is ambiguous (host:port parses validly
as both authority-form and scheme:opaque-path), and the RFC 3986
tie-break prefers the scheme reading. Callers handling HTTP request-
targets pick the entry point that matches their context:
- origin-form (
/path?query) —Uri::parse - absolute-form (
scheme://...) —Uri::parse - authority-form (
host:port, for CONNECT) —Uri::parse_authority_form - asterisk-form (
*, for OPTIONS) —Uri::parse
§Migrating from http::Uri
Notable behavioural differences for code switching from http::Uri:
- CONNECT request-targets must use
Uri::parse_authority_form.http::Uri::from_str("example.com:443")silently misparsed the target; rama’sparsefollows RFC 3986 and reads it asscheme=example.com / path=443. Proxies handling CONNECT must route through the dedicated entry point or the tie-break will quietly route wrong. - Out-of-range port →
Err.http::Urisilently discards ports outsideu16; rama returnsParseError::InvalidComponenttagged withComponent::Port. - Empty host with port (
http://:8080/) →Err.http::Uriaccepted; rama doesn’t. - Control bytes anywhere →
Err. Browsers strip CR/LF/Tab; rama refuses (smuggling defense). - Non-special schemes (
urn:,data:,mailto:) parse correctly.http::Urieither rejected them or misparsedmailto:user@…as authority-bearing. rama follows RFC 3986 opaque-path semantics.
§What lives where
Uri(this file) — the opaque public type- URI-component borrowed views:
PathRef,QueryRef,FragmentRef - URI-component owned mutable types:
Query,Fragment - Errors:
ParseError,UriError
Host-related borrowed views live with their owned counterparts in
crate::address (HostRef, DomainRef).
Scheme is Protocol; authority is
Authority; host is
Host — Uri doesn’t re-export these.
Modules§
- util
- Preserved utility submodule (re-exports the
percent_encodingcrate).
Structs§
- Fragment
- Owned fragment component (the part after
#, sans the#itself). - Fragment
Ref - Borrowed view of a URI fragment component (no leading
#). - PathMut
- Mutable view of a
Uri’s path component. - PathRef
- Borrowed view of a URI path.
- Path
Segment - One segment in a URI path — the bytes between two
/separators (or between a/and the end of the path). - Path
Segments - Iterator over the segments of a URI path. Created by
PathRef::segments. - Query
- Owned query component. Cheaply mutable in-place via the
QueryMutRAII guard. - Query
Deserialize Error - Returned by
QueryRef::deserialize/Query::deserializewhen the query string cannot be converted into the target type — type mismatch, missing required field, malformed encoding, or an escaped value being fed into a non-owning&strfield. - Query
Drain - Iterator yielding owned
QueryPairs drained from aQueryMut. Created byQueryMut::drain. - Query
Mut - Mutable view of a
Uri’s query component. - Query
Pair - One owned
name[=value]pair, cheap to clone. Produced byQueryMut::popandQueryMut::drain— popping a pair off a query doesn’t copy the byte content (the buffer is refcount-shared with the source). - Query
Pair Ref - Borrowed
name[=value]pair view. Yielded byQueryRef::pairs/Query::pairs. - Query
Pairs - Iterator over the
name[=value]pairs of a URI query string. Created byQueryRef::pairs/Query::pairs. - Query
Ref - Borrowed view of a URI query component (no leading
?). - Uri
- First-class URI value.
- UriRef
- Borrowed snapshot of a
Uri’s components.
Enums§
- Component
- Which URI component a
ParseErrororUriErrorrefers to. - Parse
Error - Reasons parsing a byte string into a
Urican fail. - Resolve
Error - Errors from
Uri::resolve/Uri::resolve_strict. - UriError
- Reasons an operation on an already-parsed
Urican fail. - Wire
Error - Error returned when a wire-form contract can’t be honoured.
Traits§
- Into
UriComponent - Sealed marker — types accepted by URI component setters.
- Into
UriInput - Marker trait for inputs accepted by
Uri::parseandUri::parse_strict.