feat(lib): implement compatibility with http crate
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user