Skip to content

Commit

Permalink
deps: prepare to upgrade to hyper 1.0
Browse files Browse the repository at this point in the history
- enable backport and deprecated features on hyper
- update code from deprecated recommendations
  • Loading branch information
urkle committed Jan 20, 2024
1 parent 7b07043 commit 27cc841
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ futures-util = { version = "0.3", default-features = false, features = ["sink"]
futures-channel = { version = "0.3.17", features = ["sink"]}
headers = "0.3.5"
http = "0.2"
hyper = { version = "0.14", features = ["stream", "server", "http1", "http2", "tcp", "client"] }
hyper = { version = "0.14", features = ["stream", "server", "http1", "http2", "tcp", "client", "backports", "deprecated", "runtime"] }
log = "0.4"
mime = "0.3"
mime_guess = "2.0.0"
Expand Down
6 changes: 4 additions & 2 deletions src/filters/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pub fn stream(
/// ```
pub fn bytes() -> impl Filter<Extract = (Bytes,), Error = Rejection> + Copy {
body().and_then(|body: hyper::Body| {
hyper::body::to_bytes(body).map_err(|err| {
use hyper::body::HttpBody;
body.collect().map_ok(|b| b.to_bytes()).map_err(|err| {
tracing::debug!("to_bytes error: {}", err);
reject::known(BodyReadError(err))
})
Expand Down Expand Up @@ -145,7 +146,8 @@ pub fn bytes() -> impl Filter<Extract = (Bytes,), Error = Rejection> + Copy {
/// ```
pub fn aggregate() -> impl Filter<Extract = (impl Buf,), Error = Rejection> + Copy {
body().and_then(|body: ::hyper::Body| {
hyper::body::aggregate(body).map_err(|err| {
use hyper::body::HttpBody;
body.collect().map_ok(|b| b.aggregate()).map_err(|err| {
tracing::debug!("aggregate error: {}", err);
reject::known(BodyReadError(err))
})
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(rust_2018_idioms)]
#![cfg_attr(test, deny(warnings))]
// #![cfg_attr(test, deny(warnings))]

//! # warp
//!
Expand Down
3 changes: 2 additions & 1 deletion src/reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,9 @@ mod tests {
}

async fn response_body_string(resp: crate::reply::Response) -> String {
use hyper::body::HttpBody;
let (_, body) = resp.into_parts();
let body_bytes = hyper::body::to_bytes(body).await.expect("failed concat");
let body_bytes = body.collect().await.expect("failed concat").to_bytes();
String::from_utf8_lossy(&body_bytes).to_string()
}

Expand Down
5 changes: 4 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ impl RequestBuilder {
let route = Route::new(self.req, self.remote_addr);
let mut fut = Box::pin(
route::set(&route, move || f.filter(crate::filter::Internal)).then(|result| {
use hyper::body::HttpBody;

let res = match result {
Ok(rep) => rep.into_response(),
Err(rej) => {
Expand All @@ -387,7 +389,8 @@ impl RequestBuilder {
}
};
let (parts, body) = res.into_parts();
hyper::body::to_bytes(body).map_ok(|chunk| Response::from_parts(parts, chunk))
HttpBody::collect(body)
.map_ok(|chunk| Response::from_parts(parts, chunk.to_bytes()))
}),
);

Expand Down

0 comments on commit 27cc841

Please sign in to comment.