feat(lib): remove extern Url type usage

BREAKING CHANGE: The `Url` type is no longer used. Any instance in the
  `Client` API has had it replaced with `hyper::Uri`.

  This also means `Error::Uri` has changed types to
  `hyper::error::UriError`.

  The type `hyper::header::parsing::HTTP_VALUE` has been made private,
  as an implementation detail. The function `http_percent_encoding`
  should be used instead.
This commit is contained in:
Sean McArthur
2017-03-21 10:35:31 -07:00
parent e81184e53c
commit 4fb7e6ebc6
12 changed files with 192 additions and 155 deletions

View File

@@ -9,10 +9,9 @@
use language_tags::LanguageTag;
use std::fmt;
use unicase::UniCase;
use url::percent_encoding;
use header::{Header, Raw, parsing};
use header::parsing::{parse_extended_value, HTTP_VALUE};
use header::parsing::{parse_extended_value, http_percent_encode};
use header::shared::Charset;
/// The implied disposition of the content of the HTTP body
@@ -182,8 +181,7 @@ impl fmt::Display for ContentDisposition {
try!(write!(f, "{}", lang));
};
try!(write!(f, "'"));
try!(f.write_str(
&percent_encoding::percent_encode(bytes, HTTP_VALUE).to_string()))
try!(http_percent_encode(f, bytes))
}
},
DispositionParam::Ext(ref k, ref v) => try!(write!(f, "; {}=\"{}\"", k, v)),

View File

@@ -9,6 +9,7 @@ use url::percent_encoding;
use header::Raw;
use header::shared::Charset;
/// Reads a single raw string when parsing a header.
pub fn from_one_raw_str<T: str::FromStr>(raw: &Raw) -> ::Result<T> {
if let Some(line) = raw.one() {
@@ -132,25 +133,11 @@ pub fn parse_extended_value(val: &str) -> ::Result<ExtendedValue> {
})
}
define_encode_set! {
/// This encode set is used for HTTP header values and is defined at
/// https://tools.ietf.org/html/rfc5987#section-3.2
pub HTTP_VALUE = [percent_encoding::SIMPLE_ENCODE_SET] | {
' ', '"', '%', '\'', '(', ')', '*', ',', '/', ':', ';', '<', '-', '>', '?',
'[', '\\', ']', '{', '}'
}
}
impl fmt::Debug for HTTP_VALUE {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("HTTP_VALUE")
}
}
impl Display for ExtendedValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let encoded_value =
percent_encoding::percent_encode(&self.value[..], HTTP_VALUE);
percent_encoding::percent_encode(&self.value[..], self::percent_encoding_http::HTTP_VALUE);
if let Some(ref lang) = self.language_tag {
write!(f, "{}'{}'{}", self.charset, lang, encoded_value)
} else {
@@ -159,6 +146,33 @@ impl Display for ExtendedValue {
}
}
/// Percent encode a sequence of bytes with a character set defined in
/// https://tools.ietf.org/html/rfc5987#section-3.2
pub fn http_percent_encode(f: &mut fmt::Formatter, bytes: &[u8]) -> fmt::Result {
let encoded = percent_encoding::percent_encode(bytes, self::percent_encoding_http::HTTP_VALUE);
fmt::Display::fmt(&encoded, f)
}
mod percent_encoding_http {
use std::fmt;
use url::percent_encoding;
define_encode_set! {
/// This encode set is used for HTTP header values and is defined at
/// https://tools.ietf.org/html/rfc5987#section-3.2
pub HTTP_VALUE = [percent_encoding::SIMPLE_ENCODE_SET] | {
' ', '"', '%', '\'', '(', ')', '*', ',', '/', ':', ';', '<', '-', '>', '?',
'[', '\\', ']', '{', '}'
}
}
impl fmt::Debug for HTTP_VALUE {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("HTTP_VALUE")
}
}
}
#[cfg(test)]
mod tests {
use header::shared::Charset;