Update to http 0.2 (#432)

This commit is contained in:
Sean McArthur
2019-12-02 16:22:26 -08:00
committed by GitHub
parent e7e75bf117
commit eab9c0b410
6 changed files with 17 additions and 10 deletions

View File

@@ -44,7 +44,7 @@ futures-util = { version = "0.3", default-features = false, features = [] }
tokio-util = { version = "0.2", features = ["codec"] }
tokio = { version = "0.2", features = ["io-util", "sync"] }
bytes = "0.5.2"
http = { git = "https://github.com/hyperium/http" } #"0.1.8"
http = "0.2"
log = "0.4.1"
fnv = "1.0.5"
slab = "0.4.0"

View File

@@ -544,7 +544,7 @@ impl Pseudo {
let mut path = parts
.path_and_query
.map(|v| v.into())
.map(|v| Bytes::copy_from_slice(v.as_str().as_bytes()))
.unwrap_or_else(Bytes::new);
if path.is_empty() && method != Method::OPTIONS {
@@ -569,7 +569,9 @@ impl Pseudo {
// If the URI includes an authority component, add it to the pseudo
// headers
if let Some(authority) = parts.authority {
pseudo.set_authority(unsafe { BytesStr::from_utf8_unchecked(authority.into()) });
pseudo.set_authority(unsafe {
BytesStr::from_utf8_unchecked(Bytes::copy_from_slice(authority.as_str().as_bytes()))
});
}
pseudo
@@ -586,7 +588,12 @@ impl Pseudo {
}
pub fn set_scheme(&mut self, scheme: uri::Scheme) {
self.scheme = Some(unsafe { BytesStr::from_utf8_unchecked(scheme.into()) });
let bytes = match scheme.as_str() {
"http" => Bytes::from_static(b"http"),
"https" => Bytes::from_static(b"https"),
s => Bytes::copy_from_slice(s.as_bytes()),
};
self.scheme = Some(unsafe { BytesStr::from_utf8_unchecked(bytes) });
}
pub fn set_authority(&mut self, authority: BytesStr) {

View File

@@ -1375,7 +1375,7 @@ impl proto::Peer for Peer {
// A request translated from HTTP/1 must not include the :authority
// header
if let Some(authority) = pseudo.authority {
let maybe_authority = uri::Authority::from_shared(authority.clone().into_inner());
let maybe_authority = uri::Authority::from_maybe_shared(authority.clone().into_inner());
parts.authority = Some(maybe_authority.or_else(|why| {
malformed!(
"malformed headers: malformed authority ({:?}): {}",
@@ -1387,7 +1387,7 @@ impl proto::Peer for Peer {
// A :scheme is always required.
if let Some(scheme) = pseudo.scheme {
let maybe_scheme = uri::Scheme::from_shared(scheme.clone().into_inner());
let maybe_scheme = scheme.parse();
let scheme = maybe_scheme.or_else(|why| {
malformed!(
"malformed headers: malformed scheme ({:?}): {}",
@@ -1412,7 +1412,7 @@ impl proto::Peer for Peer {
malformed!("malformed headers: missing path");
}
let maybe_path = uri::PathAndQuery::from_shared(path.clone().into_inner());
let maybe_path = uri::PathAndQuery::from_maybe_shared(path.clone().into_inner());
parts.path_and_query = Some(maybe_path.or_else(|why| {
malformed!("malformed headers: malformed path ({:?}): {}", path, why,)
})?);

View File

@@ -11,5 +11,5 @@ h2 = { path = "../.." }
env_logger = { version = "0.5.3", default-features = false }
futures = { version = "0.3", default-features = false }
honggfuzz = "0.5"
http = { git = "https://github.com/hyperium/http" } #"0.1.3"
http = "0.2"
tokio = { version = "0.2", features = [] }

View File

@@ -10,6 +10,6 @@ h2 = { path = "../..", features = ["unstable-stream", "unstable"] }
bytes = "0.5"
env_logger = "0.5.9"
futures = { version = "0.3", default-features = false }
http = { git = "https://github.com/hyperium/http" } #"0.1.3"
http = "0.2"
tokio = { version = "0.2", features = ["time"] }
tokio-test = "0.2"

View File

@@ -861,7 +861,7 @@ async fn request_options_with_star() {
let uri = uri::Uri::from_parts({
let mut parts = uri::Parts::default();
parts.scheme = Some(uri::Scheme::HTTP);
parts.authority = Some(uri::Authority::from_shared("example.com".into()).unwrap());
parts.authority = Some(uri::Authority::from_static("example.com"));
parts.path_and_query = Some(uri::PathAndQuery::from_static("*"));
parts
})