Skip to content

Commit

Permalink
enable tower-async-http usage in hello_hyper example
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Nov 19, 2023
1 parent 59cc2ad commit c652572
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions tower-async-hyper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions tower-async-hyper/examples/hello_hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error + Send + Sync>> {
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<Incoming>| 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")
Expand Down

0 comments on commit c652572

Please sign in to comment.