urly
Yet another URL library for ntex. The API is inspired by Python's yarl.
Url is an immutable, cheaply cloneable, normalized URL reference. It is stored
in a single ByteString, and parsing reuses the input buffer when the input is
already normalized.
- Lenient parsing with normalization: percent-encoding, IDNA hosts, dot
segments and case.
Url::validatechecks strictly against RFC 3986. - Borrowed, percent-encoded accessors (
Scheme,Authority,Path,Query,Fragment) with methods to decode them. - Path helpers:
/operator,join,parent,file_name,extension. - Query helpers:
get,get_all,set_query_pairs,extend_query_pairs,update_query_pairs,remove_query_params. BuilderandPartsfor constructing URLs from components.quote,requoteandunquoteper URL component inurly::quoting.
Usage
[]
= "0.1"
use Url;
let url = from_static;
assert_eq!;
assert_eq!;
let users = &url / "users" / "john doe";
assert_eq!;
let mut url = users.join.unwrap;
url.extend_query_pairs;
assert_eq!;
let url = builder
.scheme
.host
.path
.query_pair
.build
.unwrap;
assert_eq!;
Requoting
Parsing requotes the input instead of encoding it again, so an already-encoded URL is normalized and parsing a normalized URL returns it unchanged:
- valid
%XXescapes are kept and their hex digits are uppercased - escapes of unreserved characters (
A-Z a-z 0-9 - . _ ~) are decoded %2Fin a path is kept encoded, so it doesn't become a path separator- any other character that isn't allowed in the component is percent-encoded,
including non-ASCII characters (as UTF-8) and a
%that doesn't start a valid escape - a space is encoded as
%20, and as+in the query
Accessors return the percent-encoded component; use decode for the plain
value.
use Url;
let url = parse_ref.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
urly::quoting applies the same rules to a single value: quote encodes a
literal value, requote normalizes an encoded one and unquote decodes it.
use ;
assert_eq!;
assert_eq!;
assert_eq!;
Features
http- conversions betweenUrlandhttp::Uriserde-SerializeandDeserializeforUrl
[]
= { = "0.1", = ["http", "serde"] }
License
- Apache License, Version 2.0, (LICENSE-APACHE or [http://www.apache.org/licenses/LICENSE-2.0])
- MIT license (LICENSE-MIT or [http://opensource.org/licenses/MIT])