Skip to main content

Module base_url

Module base_url 

Source
Expand description

BaseURL and URL-reference resolution (ISO/IEC 23009-1 §5.6.5 over RFC 3986 §5, as implemented by the url crate — SP3). std only.

Moved here from transmux (#2355): the only caller was the MPD reader’s BaseURL alternates, and transmux now writes MPDs rather than fetching them. The synthetic root keeps its historical transmux-relative:/// scheme, which never leaves a result.

A DASH client turns a relative SegmentTemplate/BaseURL reference into the URL it fetches by joining a BaseURL chain onto the MPD’s own URL. With no location (an in-memory MPD) the join happens against a fixed synthetic root, transmux-relative:///, and render — the ONE place that knows about it — turns the result back into a reference.

§Containment with no base

A relative input never resolves to anything but a relative result: RFC 3986 §5.2.4 remove_dot_segments drops a .. that would climb above the root, so ../../../etc/passwd is etc/passwd, never /etc/passwd (a consumer that does local_dir.join(resolved) must not see an absolute path from an untrusted MPD). A result is absolute-path (/x) only when the MPD itself wrote an absolute-path reference (/x) in the chain or as the reference. Percent-encoded dot segments (%2e%2e) are dot segments, as in WHATWG. An input using the synthetic scheme itself is rejected (None).

The url crate implements the WHATWG URL algorithm; it differs from strict RFC 3986 in two §5.4 rows (see tests/it/base_url.rs).

Functions§

first_forbidden_char
The first control character or whitespace in s, if any.
render
The single place the synthetic root is stripped. A URL that is not under it is its own text. A synthetic URL with an authority (//host/x) keeps its //host/x form. Otherwise the path is returned as a reference: relative (the leading / of the synthetic root removed, so nothing can climb out of it) unless absolute_path says the MPD wrote an absolute-path reference.
resolve
Resolve reference against base (RFC 3986 §5.2 as the url crate implements it). base is the MPD’s own URL (a source URL, or Url::from_file_path); None for an in-memory MPD, in which case a result that stays relative is returned relative. None is returned when the reference contains a control character or whitespace (first_forbidden_char) or does not parse.
resolve_chain
Resolve a BaseURL chain (outermost first) followed by a segment reference. Each entry is joined onto the running result, so a relative entry composes with the ones above it and an absolute one resets the chain. Empty and whitespace-only entries are skipped — ISO/IEC 23009-1 §5.6.5 makes several BaseURLs alternates for the same level, so an empty one contributes nothing. None for a control character or whitespace in any entry or the reference (first_forbidden_char), for an input that names the synthetic scheme, or for a join error. With base == None a relative outcome stays relative and contained (see the module docs).