From c652572129d2b0961a7d633fb5d340325c33aee1 Mon Sep 17 00:00:00 2001 From: glendc Date: Sun, 19 Nov 2023 16:33:53 +0100 Subject: [PATCH] enable tower-async-http usage in hello_hyper example --- tower-async-hyper/Cargo.toml | 1 + tower-async-hyper/examples/hello_hyper.rs | 25 ++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tower-async-hyper/Cargo.toml b/tower-async-hyper/Cargo.toml index dd80651..e556cde 100644 --- a/tower-async-hyper/Cargo.toml +++ b/tower-async-hyper/Cargo.toml @@ -28,6 +28,7 @@ hyper-util = { version = "0.1", features = ["server", "server-auto", "tokio"] } tokio = { version = "1.0", features = ["full"] } tower-async = { path = "../tower-async", features = ["full"] } tower-async-http = { path = "../tower-async-http", features = ["full"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [package.metadata.docs.rs] all-features = true diff --git a/tower-async-hyper/examples/hello_hyper.rs b/tower-async-hyper/examples/hello_hyper.rs index 84f7cd6..a6ae62a 100644 --- a/tower-async-hyper/examples/hello_hyper.rs +++ b/tower-async-hyper/examples/hello_hyper.rs @@ -5,23 +5,34 @@ use hyper::body::Incoming; use hyper_util::rt::{TokioExecutor, TokioIo}; use hyper_util::server::conn::auto::Builder; use tokio::net::TcpListener; -use tower_async::ServiceBuilder; +use tracing_subscriber::filter::LevelFilter; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{fmt, EnvFilter}; +use tower_async::ServiceBuilder; +use tower_async_http::ServiceBuilderExt; use tower_async_hyper::TowerHyperServiceExt; #[tokio::main] async fn main() -> Result<(), Box> { + tracing_subscriber::registry() + .with(fmt::layer()) + .with( + EnvFilter::builder() + .with_default_directive(LevelFilter::DEBUG.into()) + .from_env_lossy(), + ) + .init(); + let service = ServiceBuilder::new() .timeout(std::time::Duration::from_secs(5)) .map_request(|req| req) - // .decompression() - // .compression() + .decompression() + .compression() // .follow_redirects() - // .trace_for_http() + .trace_for_http() .service_fn(|_req: Request| async move { - // req.into_body().data().await; - // let bytes = body::to_bytes(req.into_body()).await?; - // let body = String::from_utf8(bytes.to_vec()).expect("response was not valid utf-8"); Response::builder() .status(StatusCode::OK) .header("content-type", "text/plain")