feat(lib): implement compatibility with http crate

This commit is contained in:
Sam Rijs
2017-09-23 05:07:57 +10:00
committed by Sean McArthur
parent 92595e84a2
commit 0c7d375ba3
17 changed files with 535 additions and 1 deletions

View File

@@ -5,6 +5,9 @@
use std::fmt;
use std::str::FromStr;
#[cfg(feature = "compat")]
use http_types;
use error::Error;
use self::HttpVersion::{Http09, Http10, Http11, H2, H2c};
@@ -58,6 +61,39 @@ impl Default for HttpVersion {
}
}
#[cfg(feature = "compat")]
impl From<http_types::Version> for HttpVersion {
fn from(v: http_types::Version) -> HttpVersion {
match v {
http_types::Version::HTTP_09 =>
HttpVersion::Http09,
http_types::Version::HTTP_10 =>
HttpVersion::Http10,
http_types::Version::HTTP_11 =>
HttpVersion::Http11,
http_types::Version::HTTP_2 =>
HttpVersion::H2
}
}
}
#[cfg(feature = "compat")]
impl From<HttpVersion> for http_types::Version {
fn from(v: HttpVersion) -> http_types::Version {
match v {
HttpVersion::Http09 =>
http_types::Version::HTTP_09,
HttpVersion::Http10 =>
http_types::Version::HTTP_10,
HttpVersion::Http11 =>
http_types::Version::HTTP_11,
HttpVersion::H2 =>
http_types::Version::HTTP_2,
_ => panic!("attempted to convert unexpected http version")
}
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;