Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create server util to allow pulling requests #2939

Open
seanmonstar opened this issue Aug 12, 2022 · 2 comments
Open

Create server util to allow pulling requests #2939

seanmonstar opened this issue Aug 12, 2022 · 2 comments
Labels
A-server Area: server. C-feature Category: feature. This is adding a new feature. E-medium Effort: medium. Some knowledge of how hyper internal works would be useful. K-hyper-util Crate: hyper-util

Comments

@seanmonstar
Copy link
Member

The current server API is callback-based, where Service is called whenever a request is received. Some applications need to invert it such that they take a request only when they are ready. This proposes creating a utility in hyper-util that would allow usage similar to this:

// naming is hard
let (svc, rx) = hyper_util::server::puller();

let conn = Http::new().serve_connection(socket, svc);
tokio::spawn(conn);

// pull off requests
while let Some((req, tx)) = rx.next().await? {
    println!("{:?}", req);
    tx.respond(Response::new(Empty::new());
}
@seanmonstar seanmonstar added A-server Area: server. C-feature Category: feature. This is adding a new feature. E-medium Effort: medium. Some knowledge of how hyper internal works would be useful. K-hyper-util Crate: hyper-util labels Aug 12, 2022
@seanmonstar
Copy link
Member Author

@piscisaureus I think this would make it easier to fulfill the pattern you want that we discussed, yea?

@piscisaureus
Copy link

Excellent! This would go a long way.

Another integration pain point is to gracefully close the connection (stop taking new requests while finishing already existing ones). This also requires a complicated kludge - see https://github.com/denoland/deno/blob/8eed24cd3d9cea5179c65e43d23fbf6cf4d873ca/ext/http/lib.rs#L146.
(I could understand if you considered this out of scope for this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-server Area: server. C-feature Category: feature. This is adding a new feature. E-medium Effort: medium. Some knowledge of how hyper internal works would be useful. K-hyper-util Crate: hyper-util
Projects
No open projects
Status: Todo
Development

No branches or pull requests

3 participants