You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide example on how to use hyper 1.0.0 with tower layers #3154
#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error + Send + Sync>>{let addr = SocketAddr::from(([127,0,0,1],3000));// We create a TcpListener and bind it to 127.0.0.1:3000let listener = TcpListener::bind(addr).await?;// We start a loop to continuously accept incoming connectionsloop{let(stream, _) = listener.accept().await?;// Spawn a tokio task to serve multiple connections concurrently
tokio::task::spawn(asyncmove{// Finally, we bind the incoming connection to our `hello` serviceifletErr(err) = http1::Builder::new()// `service_fn` converts our function in a `Service`.serve_connection(stream,service_fn(hello)).await{println!("Error serving connection: {:?}", err);}});}}
Now hyper not relies on tower::service, so it's a bit annoying hard to reuse layer from tower::http. if other web framwork upgrade to latest hyper, would have same issue. right?
feel like it's a pity to get rid of tower service
Activity
o-agassizii commentedon Mar 16, 2023
Anyone? @seanmonstar
seanmonstar commentedon Mar 16, 2023
What have you tried so far? Where do you get stumped? The code you pasted is the hello world example.
o-agassizii commentedon Mar 31, 2023
I tried a bunch of things, all too convoluted to meaningfully describe here.
This is why I request that a super basic example is provided showing how tower layers can be combined with the lower level hello world example.
Wesley-Arizio commentedon Nov 26, 2023
@seanmonstar @o-agassizii
I have this repo with an example of an implementation of tower layer in hyper server https://github.com/Wesley-Arizio/hyper-tower, there is some stuff I need to improve but I think it's a good start.
if you guys find that is a good solution I can open a PR with this example or if you have suggestions I can implement them (or at least try to).
NewbMiao commentedon Feb 1, 2024
Now hyper not relies on tower::service, so it's a bit annoying hard to reuse layer from tower::http. if other web framwork upgrade to latest hyper, would have same issue. right?
feel like it's a pity to get rid of tower service
seanmonstar commentedon Feb 1, 2024
There's an adapter available in https://docs.rs/hyper-util/latest/hyper_util/service/struct.TowerToHyperService.html
There's also an item in #3411 to add a middleware section to the guides, if anyone would like to start that.
NewbMiao commentedon Feb 2, 2024
Cool, @seanmonstar I've had a play with the TowerToHyperService.html and also raised a PR with examples for middleware docs.