From 99b0bddac40c1dc6bc0b2e2b7513ebec565656c7 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sat, 15 Jul 2023 15:31:31 +0200 Subject: [PATCH] Update to hyper-1.0.0-rc.4 (#6) --- CHANGELOG.md | 4 +++- Cargo.toml | 5 +++-- README.md | 5 +++++ src/body.rs | 2 +- src/http_service.rs | 7 ++++--- src/lib.rs | 7 ++++++- src/service.rs | 6 +++--- src/tests.rs | 1 + 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f01d4b..f2ff982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- Update to hyper-1.0.0-rc.4 ([#6]) + +[#6]: https://github.com/davidpdrsn/tower-hyper-http-body-compat/pull/6 # 0.1.4 (13. March, 2023) diff --git a/Cargo.toml b/Cargo.toml index 604b91e..32a66f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ client = ["hyper-1/client"] http = "0.2.9" http-body-04 = { package = "http-body", version = "0.4" } http-body-1 = { package = "http-body", version = "1.0.0-rc.2" } # remember to update README.md -hyper-1 = { package = "hyper", version = "1.0.0-rc.3" } # remember to update README.md +hyper-1 = { package = "hyper", version = "1.0.0-rc.4" } # remember to update README.md pin-project-lite = "0.2.9" tower = { version = "0.4", features = ["util"] } tower-service-03 = { package = "tower-service", version = "0.3" } @@ -29,8 +29,9 @@ tower-service-03 = { package = "tower-service", version = "0.3" } axum = "0.6" bytes = "1.0" hyper-014 = { package = "hyper", version = "0.14", features = ["full"] } -hyper-1 = { package = "hyper", version = "1.0.0-rc.3", features = ["full"] } +hyper-1 = { package = "hyper", version = "1.0.0-rc.4", features = ["full"] } http-body-util = "0.1.0-rc.2" +hyper-util = { git = "https://github.com/hyperium/hyper-util", features = ["full"] } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["full", "make"] } tower-http = { version = "0.4", features = [ diff --git a/README.md b/README.md index c331a13..e4d557c 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ async fn main() -> Result<(), Box> { let mut tcp_listener = TcpListener::bind(addr).await?; loop { let (tcp_stream, _) = tcp_listener.accept().await?; + + // hyper-util isn't on crates.io yet. Instead depend on it via git + // `hyper-util = { git = "https://github.com/hyperium/hyper-util" }` + let tcp_stream = hyper_util::rt::TokioIo::new(tcp_stream); + let service = service.clone(); tokio::task::spawn(async move { if let Err(http_err) = http1::Builder::new() diff --git a/src/body.rs b/src/body.rs index 4a74b00..9e47fe3 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,6 +1,6 @@ use std::{ pin::Pin, - task::{self, Context, Poll}, + task::{Context, Poll}, }; use http::HeaderMap; diff --git a/src/http_service.rs b/src/http_service.rs index 57a0baf..fd753f9 100644 --- a/src/http_service.rs +++ b/src/http_service.rs @@ -64,6 +64,7 @@ use crate::{HttpBody04ToHttpBody1, HttpBody1ToHttpBody04}; /// let mut tcp_listener = TcpListener::bind(addr).await?; /// loop { /// let (tcp_stream, _) = tcp_listener.accept().await?; +/// let tcp_stream = hyper_util::rt::TokioIo::new(tcp_stream); /// let service = service.clone(); /// tokio::task::spawn(async move { /// if let Err(http_err) = http1::Builder::new() @@ -78,7 +79,7 @@ use crate::{HttpBody04ToHttpBody1, HttpBody1ToHttpBody04}; /// ``` /// /// [tower-service 0.3 HTTP `Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html -/// [hyper 1.0 HTTP `Service`]: https://docs.rs/hyper/1.0.0-rc.3/hyper/service/trait.Service.html +/// [hyper 1.0 HTTP `Service`]: https://docs.rs/hyper/1.0.0-rc.4/hyper/service/trait.Service.html pub struct TowerService03HttpServiceAsHyper1HttpService { service: S, _marker: PhantomData B>, @@ -136,7 +137,7 @@ where >; #[inline] - fn call(&mut self, req: Request) -> Self::Future { + fn call(&self, req: Request) -> Self::Future { let req = req.map(HttpBody1ToHttpBody04::new); TowerService03HttpServiceAsHyper1HttpServiceFuture { future: self.service.clone().oneshot(req), @@ -176,7 +177,7 @@ where /// response is [`http::Response<_>`][Response]. /// /// [tower-service 0.3 HTTP `Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html -/// [hyper 1.0 HTTP `Service`]: https://docs.rs/hyper/1.0.0-rc.3/hyper/service/trait.Service.html +/// [hyper 1.0 HTTP `Service`]: https://docs.rs/hyper/1.0.0-rc.4/hyper/service/trait.Service.html pub struct Hyper1HttpServiceAsTowerService03HttpService { service: S, _marker: PhantomData B>, diff --git a/src/lib.rs b/src/lib.rs index 7018fff..aaf26bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ //! //! The required release candidates are: //! -//! - hyper 1.0.0-rc.3 +//! - hyper 1.0.0-rc.4 //! - http-body 1.0.0-rc.2 //! //! # Example @@ -34,6 +34,11 @@ //! let mut tcp_listener = TcpListener::bind(addr).await?; //! loop { //! let (tcp_stream, _) = tcp_listener.accept().await?; +//! +//! // hyper-util isn't on crates.io yet. Instead depend on it via git +//! // `hyper-util = { git = "https://github.com/hyperium/hyper-util" }` +//! let tcp_stream = hyper_util::rt::TokioIo::new(tcp_stream); +//! //! let service = service.clone(); //! tokio::task::spawn(async move { //! if let Err(http_err) = http1::Builder::new() diff --git a/src/service.rs b/src/service.rs index 420e72b..522fd71 100644 --- a/src/service.rs +++ b/src/service.rs @@ -16,7 +16,7 @@ use tower::{util::Oneshot, ServiceExt}; /// [`TowerService03HttpServiceAsHyper1HttpService`] instead of this. /// /// [tower-service 0.3 `Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html -/// [hyper 1.0 `Service`]: https://docs.rs/hyper/1.0.0-rc.3/hyper/service/trait.Service.html +/// [hyper 1.0 `Service`]: https://docs.rs/hyper/1.0.0-rc.4/hyper/service/trait.Service.html /// [`TowerService03HttpServiceAsHyper1HttpService`]: crate::TowerService03HttpServiceAsHyper1HttpService #[derive(Clone, Copy, Debug)] pub struct TowerService03ServiceAsHyper1Service(S); @@ -37,7 +37,7 @@ where type Future = TowerService03ServiceAsHyper1ServiceFuture; #[inline] - fn call(&mut self, req: R) -> Self::Future { + fn call(&self, req: R) -> Self::Future { TowerService03ServiceAsHyper1ServiceFuture { // have to drive backpressure in the future future: self.0.clone().oneshot(req), @@ -76,7 +76,7 @@ where /// [`Hyper1HttpServiceAsTowerService03HttpService`] instead of this. /// /// [tower-service 0.3 `Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html -/// [hyper 1.0 `Service`]: https://docs.rs/hyper/1.0.0-rc.3/hyper/service/trait.Service.html +/// [hyper 1.0 `Service`]: https://docs.rs/hyper/1.0.0-rc.4/hyper/service/trait.Service.html /// [`Hyper1HttpServiceAsTowerService03HttpService`]: crate::Hyper1HttpServiceAsTowerService03HttpService #[derive(Clone, Copy, Debug)] pub struct Hyper1ServiceAsTowerService03Service(S); diff --git a/src/tests.rs b/src/tests.rs index 7a33e1d..16c5d8c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -29,6 +29,7 @@ async fn tower_service_03_service_to_hyper_1_service() { tokio::task::spawn(async move { loop { let (tcp_stream, _) = tcp_listener.accept().await.unwrap(); + let tcp_stream = hyper_util::rt::TokioIo::new(tcp_stream); tokio::spawn(async move { http1::Builder::new() .serve_connection(tcp_stream, svc)