JFLib

netpkt/uri.rs#

Source: lib/netpkt/uri.rs

uri -- URI references as RFC 3986 reads them: the generic parts of an address and the
resolution of a relative reference, percent encoding, HTML's form encoding.  No scheme's own
rules (http's default port, say) and no I/O; netio::url is the socket side's absolute URL
(that crate needs plat), jfn_sim::http::Url the simulator's.

  Uri::parse(s)                  every text is a reference (RFC 3986 appendix B): scheme (lower
                                 case; only when it has the syntax of one), authority, path,
                                 query, fragment, all as written
  u.host() / port() / userinfo() the parts of the authority (an IPv6 address without its
                                 brackets)
  base.resolve(&r) / base.join(s)   the target of a reference against a base (5.2.2, strict)
  remove_dot_segments(path)      "." and ".." out of a path (5.2.4)
  u.text()                       the reference written again (5.3)
  u.target()                     path and query as a request line wants them ("/" for no path)
  u.encoded()                    the same reference with what a URI cannot hold as %XX (spaces,
                                 umlauts, a lone %); what is escaped already stays
  percent_encode(bytes, keep) / percent_decode(s) / percent_text(s)   %XX; keep: the bytes that
                                 stay besides the unreserved ones; percent_decode leaves a bad
                                 escape as it is, percent_text is UTF-8 with U+FFFD
  form_encode(pairs) / form_decode(text)   application/x-www-form-urlencoded (HTML, WHATWG URL):
                                 a space is "+", only * - . _ and alphanumerics stay
  • struct Uri a URI reference (see the module header)
    • scheme: Option<String>
    • authority: Option<String> -- what follows "//": [userinfo@]host[:port]
    • path: String
    • query: Option<String>
    • fragment: Option<String>

impl Uri

  • fn parse(s: &str) -> Uri a reference: never fails, a text without any of the delimiters is a relative path

  • fn userinfo(&self) -> Option<&str> the user information of the authority

  • fn host(&self) -> Option<&str> the host as written (an IPv6 address without its brackets; "" when the authority has none)

  • fn port(&self) -> Option<u16> the port (None: not given, or no number up to 65535)

  • fn resolve(&self, r: &Uri) -> Uri the target of reference r against this base (RFC 3986 5.2.2, strict: a scheme equal to the base's still makes the reference absolute)

  • fn join(&self, r: &str) -> Uri resolve() of a reference given as text

  • fn text(&self) -> String the reference written again (5.3)

  • fn target(&self) -> String the path and query of a request line ("/" for an empty path, no fragment)

  • fn encoded(&self) -> Uri the reference with every character a URI cannot hold as %XX: the path's, the query's and the fragment's; what is escaped already stays, a % without two hex digits becomes %25

  • fn remove_dot_segments(path: &str) -> String "." and ".." out of a path (RFC 3986 5.2.4); ".." never climbs above the root

  • fn percent_encode(b: &[u8], keep: &[u8]) -> String %XX for every byte but the unreserved ones (RFC 3986 2.3) and those of keep

  • fn percent_decode(s: &str) -> Vec<u8> the bytes behind %XX; an escape without two hex digits stays as it is

  • fn percent_text(s: &str) -> String percent_decode as text: UTF-8, what is none becomes U+FFFD

  • fn form_encode(pairs: &[(String, String)]) -> String name / value pairs as a form sends them (application/x-www-form-urlencoded)

  • fn form_decode(text: &str) -> Vec<(String, String)> the name / value pairs of a query or a form's body, decoded in their order ("+" is a space)

Source: docs/API.md in the JFLib repository.