style(rustfmt): run rustfmt on hyper correct overlong lines
This commit is contained in:
@@ -108,7 +108,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_into_inner() {
|
fn test_into_inner() {
|
||||||
let message: Box<HttpMessage> = Box::new(Http11Message::with_stream(Box::new(MockStream::new())));
|
let message: Box<HttpMessage> = Box::new(
|
||||||
|
Http11Message::with_stream(Box::new(MockStream::new())));
|
||||||
let message = message.downcast::<Http11Message>().ok().unwrap();
|
let message = message.downcast::<Http11Message>().ok().unwrap();
|
||||||
let b = message.into_inner().downcast::<MockStream>().ok().unwrap();
|
let b = message.into_inner().downcast::<MockStream>().ok().unwrap();
|
||||||
assert_eq!(b, Box::new(MockStream::new()));
|
assert_eq!(b, Box::new(MockStream::new()));
|
||||||
|
|||||||
@@ -211,7 +211,8 @@ mod tests {
|
|||||||
fn test_from_ssl() {
|
fn test_from_ssl() {
|
||||||
use openssl::ssl::error::SslError;
|
use openssl::ssl::error::SslError;
|
||||||
|
|
||||||
from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl negotiation")) => Io(..));
|
from!(SslError::StreamError(
|
||||||
|
io::Error::new(io::ErrorKind::Other, "ssl negotiation")) => Io(..));
|
||||||
from_and_cause!(SslError::SslSessionClosed => Ssl(..));
|
from_and_cause!(SslError::SslSessionClosed => Ssl(..));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,11 +61,12 @@ header! {
|
|||||||
#[doc="headers.set("]
|
#[doc="headers.set("]
|
||||||
#[doc=" Accept(vec!["]
|
#[doc=" Accept(vec!["]
|
||||||
#[doc=" qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),"]
|
#[doc=" qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),"]
|
||||||
#[doc=" qitem(Mime(TopLevel::Application, SubLevel::Ext(\"xhtml+xml\".to_owned()), vec![])),"]
|
#[doc=" qitem(Mime(TopLevel::Application,"]
|
||||||
|
#[doc=" SubLevel::Ext(\"xhtml+xml\".to_owned()), vec![])),"]
|
||||||
#[doc=" QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]),"]
|
#[doc=" QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]),"]
|
||||||
#[doc=" Quality(900)),"]
|
#[doc=" Quality(900)),"]
|
||||||
#[doc=" qitem(Mime(TopLevel::Image, SubLevel::Ext(\"webp\".to_owned()), vec![])),
|
#[doc=" qitem(Mime(TopLevel::Image,"]
|
||||||
"]
|
#[doc=" SubLevel::Ext(\"webp\".to_owned()), vec![])),"]
|
||||||
#[doc=" QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]),"]
|
#[doc=" QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]),"]
|
||||||
#[doc=" Quality(800))"]
|
#[doc=" Quality(800))"]
|
||||||
#[doc=" ])"]
|
#[doc=" ])"]
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ mod tests {
|
|||||||
fn test_parse() {
|
fn test_parse() {
|
||||||
assert_eq!(Connection::close(),parse_option(b"close".to_vec()));
|
assert_eq!(Connection::close(),parse_option(b"close".to_vec()));
|
||||||
assert_eq!(Connection::keep_alive(),parse_option(b"keep-alive".to_vec()));
|
assert_eq!(Connection::keep_alive(),parse_option(b"keep-alive".to_vec()));
|
||||||
assert_eq!(Connection(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]),parse_option(b"upgrade".to_vec()));
|
assert_eq!(Connection(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]),
|
||||||
|
parse_option(b"upgrade".to_vec()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ header! {
|
|||||||
#[doc="let mut headers = Headers::new();"]
|
#[doc="let mut headers = Headers::new();"]
|
||||||
#[doc="headers.set(Referer(\"http://www.example.com/index.html\".to_owned()));"]
|
#[doc="headers.set(Referer(\"http://www.example.com/index.html\".to_owned()));"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
// TODO: Use URL
|
// TODO Use URL
|
||||||
(Referer, "Referer") => [String]
|
(Referer, "Referer") => [String]
|
||||||
|
|
||||||
test_referer {
|
test_referer {
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ header! {
|
|||||||
#[doc="headers.set("]
|
#[doc="headers.set("]
|
||||||
#[doc=" Upgrade(vec!["]
|
#[doc=" Upgrade(vec!["]
|
||||||
#[doc=" Protocol::new(ProtocolName::Http, Some(\"2.0\".to_owned())),"]
|
#[doc=" Protocol::new(ProtocolName::Http, Some(\"2.0\".to_owned())),"]
|
||||||
#[doc=" Protocol::new(ProtocolName::Unregistered(\"SHTTP\".to_owned()), Some(\"1.3\".to_owned())),"]
|
#[doc=" Protocol::new(ProtocolName::Unregistered(\"SHTTP\".to_owned()),"]
|
||||||
#[doc=" Protocol::new(ProtocolName::Unregistered(\"IRC\".to_owned()), Some(\"6.9\".to_owned())),"]
|
#[doc=" Some(\"1.3\".to_owned())),"]
|
||||||
#[doc=" Protocol::new(ProtocolName::Unregistered(\"RTA\".to_owned()), Some(\"x11\".to_owned())),"]
|
#[doc=" Protocol::new(ProtocolName::Unregistered(\"IRC\".to_owned()),"]
|
||||||
|
#[doc=" Some(\"6.9\".to_owned())),"]
|
||||||
#[doc=" ])"]
|
#[doc=" ])"]
|
||||||
#[doc=");"]
|
#[doc=");"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
@@ -56,7 +57,8 @@ header! {
|
|||||||
vec![b"HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"],
|
vec![b"HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"],
|
||||||
Some(Upgrade(vec![
|
Some(Upgrade(vec![
|
||||||
Protocol::new(ProtocolName::Http, Some("2.0".to_owned())),
|
Protocol::new(ProtocolName::Http, Some("2.0".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("SHTTP".to_owned()), Some("1.3".to_owned())),
|
Protocol::new(ProtocolName::Unregistered("SHTTP".to_owned()),
|
||||||
|
Some("1.3".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("IRC".to_owned()), Some("6.9".to_owned())),
|
Protocol::new(ProtocolName::Unregistered("IRC".to_owned()), Some("6.9".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("RTA".to_owned()), Some("x11".to_owned())),
|
Protocol::new(ProtocolName::Unregistered("RTA".to_owned()), Some("x11".to_owned())),
|
||||||
])));
|
])));
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ impl Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> ::Result<Box<HeaderFormat + Send + Sync>> {
|
fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) ->
|
||||||
|
::Result<Box<HeaderFormat + Send + Sync>> {
|
||||||
Header::parse_header(&raw[..]).map(|h: H| {
|
Header::parse_header(&raw[..]).map(|h: H| {
|
||||||
// FIXME: Use Type ascription
|
// FIXME: Use Type ascription
|
||||||
let h: Box<HeaderFormat + Send + Sync> = Box::new(h);
|
let h: Box<HeaderFormat + Send + Sync> = Box::new(h);
|
||||||
@@ -101,7 +102,8 @@ impl fmt::Display for Item {
|
|||||||
match from_utf8(&part[..]) {
|
match from_utf8(&part[..]) {
|
||||||
Ok(s) => try!(f.write_str(s)),
|
Ok(s) => try!(f.write_str(s)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("raw header value is not utf8. header={:?}, error={:?}", part, e);
|
error!("raw header value is not utf8. header={:?}, error={:?}",
|
||||||
|
part, e);
|
||||||
return Err(fmt::Error);
|
return Err(fmt::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ impl Headers {
|
|||||||
/// # let mut headers = Headers::new();
|
/// # let mut headers = Headers::new();
|
||||||
/// headers.set_raw("content-length", vec![b"5".to_vec()]);
|
/// headers.set_raw("content-length", vec![b"5".to_vec()]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_raw<K: Into<Cow<'static, str>> + fmt::Debug>(&mut self, name: K, value: Vec<Vec<u8>>) {
|
pub fn set_raw<K: Into<Cow<'static, str>> + fmt::Debug>(&mut self, name: K,
|
||||||
|
value: Vec<Vec<u8>>) {
|
||||||
trace!("Headers.set_raw( {:?}, {:?} )", name, value);
|
trace!("Headers.set_raw( {:?}, {:?} )", name, value);
|
||||||
self.data.insert(UniCase(CowStr(name.into())), Item::new_raw(value));
|
self.data.insert(UniCase(CowStr(name.into())), Item::new_raw(value));
|
||||||
}
|
}
|
||||||
@@ -252,12 +253,14 @@ impl Headers {
|
|||||||
|
|
||||||
/// Get a reference to the header field's value, if it exists.
|
/// Get a reference to the header field's value, if it exists.
|
||||||
pub fn get<H: Header + HeaderFormat>(&self) -> Option<&H> {
|
pub fn get<H: Header + HeaderFormat>(&self) -> Option<&H> {
|
||||||
self.data.get(&UniCase(CowStr(Cow::Borrowed(header_name::<H>())))).and_then(Item::typed::<H>)
|
self.data.get(&UniCase(CowStr(Cow::Borrowed(header_name::<H>()))))
|
||||||
|
.and_then(Item::typed::<H>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to the header field's value, if it exists.
|
/// Get a mutable reference to the header field's value, if it exists.
|
||||||
pub fn get_mut<H: Header + HeaderFormat>(&mut self) -> Option<&mut H> {
|
pub fn get_mut<H: Header + HeaderFormat>(&mut self) -> Option<&mut H> {
|
||||||
self.data.get_mut(&UniCase(CowStr(Cow::Borrowed(header_name::<H>())))).and_then(Item::typed_mut::<H>)
|
self.data.get_mut(&UniCase(CowStr(Cow::Borrowed(header_name::<H>()))))
|
||||||
|
.and_then(Item::typed_mut::<H>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a boolean of whether a certain header is in the map.
|
/// Returns a boolean of whether a certain header is in the map.
|
||||||
@@ -509,7 +512,8 @@ mod tests {
|
|||||||
let accept = Header::parse_header([b"text/plain".to_vec()].as_ref());
|
let accept = Header::parse_header([b"text/plain".to_vec()].as_ref());
|
||||||
assert_eq!(accept.ok(), Some(Accept(vec![text_plain.clone()])));
|
assert_eq!(accept.ok(), Some(Accept(vec![text_plain.clone()])));
|
||||||
|
|
||||||
let accept = Header::parse_header([b"application/vnd.github.v3.full+json; q=0.5, text/plain".to_vec()].as_ref());
|
let bytevec = [b"application/vnd.github.v3.full+json; q=0.5, text/plain".to_vec()];
|
||||||
|
let accept = Header::parse_header(bytevec.as_ref());
|
||||||
assert_eq!(accept.ok(), Some(Accept(vec![application_vendor, text_plain])));
|
assert_eq!(accept.ok(), Some(Accept(vec![application_vendor, text_plain])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +572,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_different_reads() {
|
fn test_different_reads() {
|
||||||
let headers = Headers::from_raw(&raw!(b"Content-Length: 10", b"Content-Type: text/plain")).unwrap();
|
let headers = Headers::from_raw(
|
||||||
|
&raw!(b"Content-Length: 10", b"Content-Type: text/plain")).unwrap();
|
||||||
let ContentLength(_) = *headers.get::<ContentLength>().unwrap();
|
let ContentLength(_) = *headers.get::<ContentLength>().unwrap();
|
||||||
let ContentType(_) = *headers.get::<ContentType>().unwrap();
|
let ContentType(_) = *headers.get::<ContentType>().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,22 @@ impl EntityTag {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
/// If the tag contains invalid characters.
|
/// If the tag contains invalid characters.
|
||||||
pub fn new(weak: bool, tag: String) -> EntityTag {
|
pub fn new(weak: bool, tag: String) -> EntityTag {
|
||||||
match check_slice_validity(&tag) {
|
assert!(check_slice_validity(&tag), "Invalid tag: {:?}", tag);
|
||||||
true => EntityTag { weak: weak, tag: tag },
|
EntityTag { weak: weak, tag: tag }
|
||||||
false => panic!("Invalid tag: {:?}", tag),
|
}
|
||||||
}
|
|
||||||
|
/// Constructs a new weak EntityTag.
|
||||||
|
/// # Panics
|
||||||
|
/// If the tag contains invalid characters.
|
||||||
|
pub fn weak(tag: String) -> EntityTag {
|
||||||
|
EntityTag::new(true, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constructs a new strong EntityTag.
|
||||||
|
/// # Panics
|
||||||
|
/// If the tag contains invalid characters.
|
||||||
|
pub fn strong(tag: String) -> EntityTag {
|
||||||
|
EntityTag::new(false, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the tag.
|
/// Get the tag.
|
||||||
@@ -67,16 +79,14 @@ impl EntityTag {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
/// If the tag contains invalid characters.
|
/// If the tag contains invalid characters.
|
||||||
pub fn set_tag(&mut self, tag: String) {
|
pub fn set_tag(&mut self, tag: String) {
|
||||||
match check_slice_validity(&tag[..]) {
|
assert!(check_slice_validity(&tag), "Invalid tag: {:?}", tag);
|
||||||
true => self.tag = tag,
|
self.tag = tag
|
||||||
false => panic!("Invalid tag: {:?}", tag),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For strong comparison two entity-tags are equivalent if both are not weak and their
|
/// For strong comparison two entity-tags are equivalent if both are not weak and their
|
||||||
/// opaque-tags match character-by-character.
|
/// opaque-tags match character-by-character.
|
||||||
pub fn strong_eq(&self, other: &EntityTag) -> bool {
|
pub fn strong_eq(&self, other: &EntityTag) -> bool {
|
||||||
self.weak == false && other.weak == false && self.tag == other.tag
|
!self.weak && !other.weak && self.tag == other.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For weak comparison two entity-tags are equivalent if their
|
/// For weak comparison two entity-tags are equivalent if their
|
||||||
@@ -134,11 +144,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_etag_parse_success() {
|
fn test_etag_parse_success() {
|
||||||
// Expected success
|
// Expected success
|
||||||
assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "foobar".to_owned()));
|
assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(),
|
||||||
assert_eq!("\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "".to_owned()));
|
EntityTag::strong("foobar".to_owned()));
|
||||||
assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "weaktag".to_owned()));
|
assert_eq!("\"\"".parse::<EntityTag>().unwrap(),
|
||||||
assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "\x65\x62".to_owned()));
|
EntityTag::strong("".to_owned()));
|
||||||
assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "".to_owned()));
|
assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(),
|
||||||
|
EntityTag::weak("weaktag".to_owned()));
|
||||||
|
assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(),
|
||||||
|
EntityTag::weak("\x65\x62".to_owned()));
|
||||||
|
assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::weak("".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -154,11 +168,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_etag_fmt() {
|
fn test_etag_fmt() {
|
||||||
assert_eq!(format!("{}", EntityTag::new(false, "foobar".to_owned())), "\"foobar\"");
|
assert_eq!(format!("{}", EntityTag::strong("foobar".to_owned())), "\"foobar\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(false, "".to_owned())), "\"\"");
|
assert_eq!(format!("{}", EntityTag::strong("".to_owned())), "\"\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "weak-etag".to_owned())), "W/\"weak-etag\"");
|
assert_eq!(format!("{}", EntityTag::weak("weak-etag".to_owned())), "W/\"weak-etag\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "\u{0065}".to_owned())), "W/\"\x65\"");
|
assert_eq!(format!("{}", EntityTag::weak("\u{0065}".to_owned())), "W/\"\x65\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "".to_owned())), "W/\"\"");
|
assert_eq!(format!("{}", EntityTag::weak("".to_owned())), "W/\"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -169,32 +183,32 @@ mod tests {
|
|||||||
// | `W/"1"` | `W/"2"` | no match | no match |
|
// | `W/"1"` | `W/"2"` | no match | no match |
|
||||||
// | `W/"1"` | `"1"` | no match | match |
|
// | `W/"1"` | `"1"` | no match | match |
|
||||||
// | `"1"` | `"1"` | match | match |
|
// | `"1"` | `"1"` | match | match |
|
||||||
let mut etag1 = EntityTag::new(true, "1".to_owned());
|
let mut etag1 = EntityTag::weak("1".to_owned());
|
||||||
let mut etag2 = EntityTag::new(true, "1".to_owned());
|
let mut etag2 = EntityTag::weak("1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert!(!etag1.strong_eq(&etag2));
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert!(etag1.weak_eq(&etag2));
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert!(etag1.strong_ne(&etag2));
|
||||||
assert_eq!(etag1.weak_ne(&etag2), false);
|
assert!(!etag1.weak_ne(&etag2));
|
||||||
|
|
||||||
etag1 = EntityTag::new(true, "1".to_owned());
|
etag1 = EntityTag::weak("1".to_owned());
|
||||||
etag2 = EntityTag::new(true, "2".to_owned());
|
etag2 = EntityTag::weak("2".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert!(!etag1.strong_eq(&etag2));
|
||||||
assert_eq!(etag1.weak_eq(&etag2), false);
|
assert!(!etag1.weak_eq(&etag2));
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert!(etag1.strong_ne(&etag2));
|
||||||
assert_eq!(etag1.weak_ne(&etag2), true);
|
assert!(etag1.weak_ne(&etag2));
|
||||||
|
|
||||||
etag1 = EntityTag::new(true, "1".to_owned());
|
etag1 = EntityTag::weak("1".to_owned());
|
||||||
etag2 = EntityTag::new(false, "1".to_owned());
|
etag2 = EntityTag::strong("1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert!(!etag1.strong_eq(&etag2));
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert!(etag1.weak_eq(&etag2));
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert!(etag1.strong_ne(&etag2));
|
||||||
assert_eq!(etag1.weak_ne(&etag2), false);
|
assert!(!etag1.weak_ne(&etag2));
|
||||||
|
|
||||||
etag1 = EntityTag::new(false, "1".to_owned());
|
etag1 = EntityTag::strong("1".to_owned());
|
||||||
etag2 = EntityTag::new(false, "1".to_owned());
|
etag2 = EntityTag::strong("1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), true);
|
assert!(etag1.strong_eq(&etag2));
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert!(etag1.weak_eq(&etag2));
|
||||||
assert_eq!(etag1.strong_ne(&etag2), false);
|
assert!(!etag1.strong_ne(&etag2));
|
||||||
assert_eq!(etag1.weak_ne(&etag2), false);
|
assert!(!etag1.weak_ne(&etag2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,7 +280,8 @@ impl Http11Protocol {
|
|||||||
|
|
||||||
struct ConnAdapter<C: NetworkConnector + Send + Sync>(C);
|
struct ConnAdapter<C: NetworkConnector + Send + Sync>(C);
|
||||||
|
|
||||||
impl<C: NetworkConnector<Stream=S> + Send + Sync, S: NetworkStream + Send> NetworkConnector for ConnAdapter<C> {
|
impl<C: NetworkConnector<Stream=S> + Send + Sync, S: NetworkStream + Send>
|
||||||
|
NetworkConnector for ConnAdapter<C> {
|
||||||
type Stream = Box<NetworkStream + Send>;
|
type Stream = Box<NetworkStream + Send>;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn connect(&self, host: &str, port: u16, scheme: &str)
|
fn connect(&self, host: &str, port: u16, scheme: &str)
|
||||||
@@ -668,7 +669,8 @@ fn try_parse<R: Read, T: TryParse<Subject=I>, I>(rdr: &mut BufReader<R>) -> TryP
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
trait TryParse {
|
trait TryParse {
|
||||||
type Subject;
|
type Subject;
|
||||||
fn try_parse<'a>(headers: &'a mut [httparse::Header<'a>], buf: &'a [u8]) -> TryParseResult<Self::Subject>;
|
fn try_parse<'a>(headers: &'a mut [httparse::Header<'a>], buf: &'a [u8]) ->
|
||||||
|
TryParseResult<Self::Subject>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TryParseResult<T> = Result<httparse::Status<(Incoming<T>, usize)>, Error>;
|
type TryParseResult<T> = Result<httparse::Status<(Incoming<T>, usize)>, Error>;
|
||||||
@@ -676,7 +678,8 @@ type TryParseResult<T> = Result<httparse::Status<(Incoming<T>, usize)>, Error>;
|
|||||||
impl<'a> TryParse for httparse::Request<'a, 'a> {
|
impl<'a> TryParse for httparse::Request<'a, 'a> {
|
||||||
type Subject = (Method, RequestUri);
|
type Subject = (Method, RequestUri);
|
||||||
|
|
||||||
fn try_parse<'b>(headers: &'b mut [httparse::Header<'b>], buf: &'b [u8]) -> TryParseResult<(Method, RequestUri)> {
|
fn try_parse<'b>(headers: &'b mut [httparse::Header<'b>], buf: &'b [u8]) ->
|
||||||
|
TryParseResult<(Method, RequestUri)> {
|
||||||
let mut req = httparse::Request::new(headers);
|
let mut req = httparse::Request::new(headers);
|
||||||
Ok(match try!(req.parse(buf)) {
|
Ok(match try!(req.parse(buf)) {
|
||||||
httparse::Status::Complete(len) => {
|
httparse::Status::Complete(len) => {
|
||||||
@@ -697,7 +700,8 @@ impl<'a> TryParse for httparse::Request<'a, 'a> {
|
|||||||
impl<'a> TryParse for httparse::Response<'a, 'a> {
|
impl<'a> TryParse for httparse::Response<'a, 'a> {
|
||||||
type Subject = RawStatus;
|
type Subject = RawStatus;
|
||||||
|
|
||||||
fn try_parse<'b>(headers: &'b mut [httparse::Header<'b>], buf: &'b [u8]) -> TryParseResult<RawStatus> {
|
fn try_parse<'b>(headers: &'b mut [httparse::Header<'b>], buf: &'b [u8]) ->
|
||||||
|
TryParseResult<RawStatus> {
|
||||||
let mut res = httparse::Response::new(headers);
|
let mut res = httparse::Response::new(headers);
|
||||||
Ok(match try!(res.parse(buf)) {
|
Ok(match try!(res.parse(buf)) {
|
||||||
httparse::Status::Complete(len) => {
|
httparse::Status::Complete(len) => {
|
||||||
@@ -773,7 +777,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_err(s: &str) {
|
fn read_err(s: &str) {
|
||||||
assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap_err().kind(), io::ErrorKind::InvalidInput);
|
assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap_err().kind(),
|
||||||
|
io::ErrorKind::InvalidInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
read("1\r\n", 1);
|
read("1\r\n", 1);
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ macro_rules! mock_connector (
|
|||||||
|
|
||||||
impl ::net::NetworkConnector for $name {
|
impl ::net::NetworkConnector for $name {
|
||||||
type Stream = ::mock::MockStream;
|
type Stream = ::mock::MockStream;
|
||||||
fn connect(&self, host: &str, port: u16, scheme: &str) -> $crate::Result<::mock::MockStream> {
|
fn connect(&self, host: &str, port: u16, scheme: &str)
|
||||||
|
-> $crate::Result<::mock::MockStream> {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
debug!("MockStream::connect({:?}, {:?}, {:?})", host, port, scheme);
|
debug!("MockStream::connect({:?}, {:?}, {:?})", host, port, scheme);
|
||||||
|
|||||||
@@ -77,4 +77,3 @@ impl<T: Send + 'static> Drop for Sentinel<T> {
|
|||||||
let _ = self.supervisor.send(self.value.take().unwrap());
|
let _ = self.supervisor.send(self.value.take().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,8 @@ impl<L: NetworkListener + Send + 'static> Server<L> {
|
|||||||
}
|
}
|
||||||
/// Binds to a socket and starts handling connections with the provided
|
/// Binds to a socket and starts handling connections with the provided
|
||||||
/// number of threads.
|
/// number of threads.
|
||||||
pub fn handle_threads<H: Handler + 'static>(self, handler: H, threads: usize) -> ::Result<Listening> {
|
pub fn handle_threads<H: Handler + 'static>(self, handler: H,
|
||||||
|
threads: usize) -> ::Result<Listening> {
|
||||||
with_listener(handler, self.listener, threads)
|
with_listener(handler, self.listener, threads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,7 +233,8 @@ impl<'a, H: Handler + 'static> Worker<'a, H> {
|
|||||||
debug!("keep_alive loop ending for {}", addr);
|
debug!("keep_alive loop ending for {}", addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keep_alive_loop<W: Write>(&self, mut rdr: BufReader<&mut NetworkStream>, mut wrt: W, addr: SocketAddr) {
|
fn keep_alive_loop<W: Write>(&self, mut rdr: BufReader<&mut NetworkStream>,
|
||||||
|
mut wrt: W, addr: SocketAddr) {
|
||||||
let mut keep_alive = true;
|
let mut keep_alive = true;
|
||||||
while keep_alive {
|
while keep_alive {
|
||||||
let req = match Request::new(&mut rdr, addr) {
|
let req = match Request::new(&mut rdr, addr) {
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ impl<'a, W: Any> Response<'a, W> {
|
|||||||
|
|
||||||
fn write_head(&mut self) -> io::Result<Body> {
|
fn write_head(&mut self) -> io::Result<Body> {
|
||||||
debug!("writing head: {:?} {:?}", self.version, self.status);
|
debug!("writing head: {:?} {:?}", self.version, self.status);
|
||||||
try!(write!(&mut self.body, "{} {}{}{}", self.version, self.status, CR as char, LF as char));
|
try!(write!(&mut self.body, "{} {}{}{}", self.version, self.status,
|
||||||
|
CR as char, LF as char));
|
||||||
|
|
||||||
if !self.headers.has::<header::Date>() {
|
if !self.headers.has::<header::Date>() {
|
||||||
self.headers.set(header::Date(header::HttpDate(now_utc())));
|
self.headers.set(header::Date(header::HttpDate(now_utc())));
|
||||||
@@ -123,7 +124,8 @@ impl<'a, W: Any> Response<'a, W> {
|
|||||||
impl<'a> Response<'a, Fresh> {
|
impl<'a> Response<'a, Fresh> {
|
||||||
/// Creates a new Response that can be used to write to a network stream.
|
/// Creates a new Response that can be used to write to a network stream.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(stream: &'a mut (Write + 'a), headers: &'a mut header::Headers) -> Response<'a, Fresh> {
|
pub fn new(stream: &'a mut (Write + 'a), headers: &'a mut header::Headers) ->
|
||||||
|
Response<'a, Fresh> {
|
||||||
Response {
|
Response {
|
||||||
status: status::StatusCode::Ok,
|
status: status::StatusCode::Ok,
|
||||||
version: version::HttpVersion::Http11,
|
version: version::HttpVersion::Http11,
|
||||||
@@ -168,7 +170,8 @@ impl<'a> Response<'a, Fresh> {
|
|||||||
stream.end()
|
stream.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume this Response<Fresh>, writing the Headers and Status and creating a Response<Streaming>
|
/// Consume this Response<Fresh>, writing the Headers and Status and
|
||||||
|
/// creating a Response<Streaming>
|
||||||
pub fn start(mut self) -> io::Result<Response<'a, Streaming>> {
|
pub fn start(mut self) -> io::Result<Response<'a, Streaming>> {
|
||||||
let body_type = try!(self.write_head());
|
let body_type = try!(self.write_head());
|
||||||
let (version, body, status, headers) = self.deconstruct();
|
let (version, body, status, headers) = self.deconstruct();
|
||||||
|
|||||||
@@ -691,7 +691,8 @@ mod tests {
|
|||||||
validate(404, NotFound, BadRequest, Some("Not Found"));
|
validate(404, NotFound, BadRequest, Some("Not Found"));
|
||||||
validate(405, MethodNotAllowed, BadRequest, Some("Method Not Allowed"));
|
validate(405, MethodNotAllowed, BadRequest, Some("Method Not Allowed"));
|
||||||
validate(406, NotAcceptable, BadRequest, Some("Not Acceptable"));
|
validate(406, NotAcceptable, BadRequest, Some("Not Acceptable"));
|
||||||
validate(407, ProxyAuthenticationRequired, BadRequest, Some("Proxy Authentication Required"));
|
validate(407, ProxyAuthenticationRequired, BadRequest,
|
||||||
|
Some("Proxy Authentication Required"));
|
||||||
validate(408, RequestTimeout, BadRequest, Some("Request Timeout"));
|
validate(408, RequestTimeout, BadRequest, Some("Request Timeout"));
|
||||||
validate(409, Conflict, BadRequest, Some("Conflict"));
|
validate(409, Conflict, BadRequest, Some("Conflict"));
|
||||||
validate(410, Gone, BadRequest, Some("Gone"));
|
validate(410, Gone, BadRequest, Some("Gone"));
|
||||||
@@ -709,19 +710,22 @@ mod tests {
|
|||||||
validate(426, UpgradeRequired, BadRequest, Some("Upgrade Required"));
|
validate(426, UpgradeRequired, BadRequest, Some("Upgrade Required"));
|
||||||
validate(428, PreconditionRequired, BadRequest, Some("Precondition Required"));
|
validate(428, PreconditionRequired, BadRequest, Some("Precondition Required"));
|
||||||
validate(429, TooManyRequests, BadRequest, Some("Too Many Requests"));
|
validate(429, TooManyRequests, BadRequest, Some("Too Many Requests"));
|
||||||
validate(431, RequestHeaderFieldsTooLarge, BadRequest, Some("Request Header Fields Too Large"));
|
validate(431, RequestHeaderFieldsTooLarge, BadRequest,
|
||||||
|
Some("Request Header Fields Too Large"));
|
||||||
|
|
||||||
validate(500, InternalServerError, InternalServerError, Some("Internal Server Error"));
|
validate(500, InternalServerError, InternalServerError, Some("Internal Server Error"));
|
||||||
validate(501, NotImplemented, InternalServerError, Some("Not Implemented"));
|
validate(501, NotImplemented, InternalServerError, Some("Not Implemented"));
|
||||||
validate(502, BadGateway, InternalServerError, Some("Bad Gateway"));
|
validate(502, BadGateway, InternalServerError, Some("Bad Gateway"));
|
||||||
validate(503, ServiceUnavailable, InternalServerError, Some("Service Unavailable"));
|
validate(503, ServiceUnavailable, InternalServerError, Some("Service Unavailable"));
|
||||||
validate(504, GatewayTimeout, InternalServerError, Some("Gateway Timeout"));
|
validate(504, GatewayTimeout, InternalServerError, Some("Gateway Timeout"));
|
||||||
validate(505, HttpVersionNotSupported, InternalServerError, Some("HTTP Version Not Supported"));
|
validate(505, HttpVersionNotSupported, InternalServerError,
|
||||||
|
Some("HTTP Version Not Supported"));
|
||||||
validate(506, VariantAlsoNegotiates, InternalServerError, Some("Variant Also Negotiates"));
|
validate(506, VariantAlsoNegotiates, InternalServerError, Some("Variant Also Negotiates"));
|
||||||
validate(507, InsufficientStorage, InternalServerError, Some("Insufficient Storage"));
|
validate(507, InsufficientStorage, InternalServerError, Some("Insufficient Storage"));
|
||||||
validate(508, LoopDetected, InternalServerError, Some("Loop Detected"));
|
validate(508, LoopDetected, InternalServerError, Some("Loop Detected"));
|
||||||
validate(510, NotExtended, InternalServerError, Some("Not Extended"));
|
validate(510, NotExtended, InternalServerError, Some("Not Extended"));
|
||||||
validate(511, NetworkAuthenticationRequired, InternalServerError, Some("Network Authentication Required"));
|
validate(511, NetworkAuthenticationRequired, InternalServerError,
|
||||||
|
Some("Network Authentication Required"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,5 +83,3 @@ fn test_uri_fromstr() {
|
|||||||
read("hyper.rs", RequestUri::Authority("hyper.rs".to_owned()));
|
read("hyper.rs", RequestUri::Authority("hyper.rs".to_owned()));
|
||||||
read("/", RequestUri::AbsolutePath("/".to_owned()));
|
read("/", RequestUri::AbsolutePath("/".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,4 +29,3 @@ impl fmt::Display for HttpVersion {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user