Skip to content

Commit

Permalink
Update to hyper-1.0.0-rc.4 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn authored Jul 15, 2023
1 parent cbaa7df commit 99b0bdd
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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 = [
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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()
Expand Down
2 changes: 1 addition & 1 deletion src/body.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
pin::Pin,
task::{self, Context, Poll},
task::{Context, Poll},
};

use http::HeaderMap;
Expand Down
7 changes: 4 additions & 3 deletions src/http_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<S, B> {
service: S,
_marker: PhantomData<fn() -> B>,
Expand Down Expand Up @@ -136,7 +137,7 @@ where
>;

#[inline]
fn call(&mut self, req: Request<ReqBody>) -> Self::Future {
fn call(&self, req: Request<ReqBody>) -> Self::Future {
let req = req.map(HttpBody1ToHttpBody04::new);
TowerService03HttpServiceAsHyper1HttpServiceFuture {
future: self.service.clone().oneshot(req),
Expand Down Expand Up @@ -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<S, B> {
service: S,
_marker: PhantomData<fn() -> B>,
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(S);
Expand All @@ -37,7 +37,7 @@ where
type Future = TowerService03ServiceAsHyper1ServiceFuture<S, R>;

#[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),
Expand Down Expand Up @@ -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>(S);
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 99b0bdd

Please sign in to comment.