Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
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

Add HTTP/2 push support to Server #1586

Open
vbrandl opened this issue Jun 28, 2018 · 3 comments
Open

Add HTTP/2 push support to Server #1586

vbrandl opened this issue Jun 28, 2018 · 3 comments

Comments

@vbrandl
Copy link

@vbrandl vbrandl commented Jun 28, 2018

What is the state of HTTP/2 server push in hyper? I couldn't find anything in the documentation. Are there any plans to implement it in the future?

@seanmonstar

This comment has been minimized.

Copy link
Member

@seanmonstar seanmonstar commented Jun 28, 2018

First step is that the h2 dependency would need Push support: hyperium/h2#291

@seanmonstar

This comment has been minimized.

Copy link
Member

@seanmonstar seanmonstar commented Dec 14, 2019

With h2 supporting push promises, I'd like to start proposing an API to support them in hyper, initially from the server side:

  • We'd add a hyper::push module to contain these new pieces.
  • Add a pusher(req: &mut http::Request) -> hyper::Result<Pusher> that can get a Pusher related the request's stream, or an Error explaining why a Pusher wasn't available. Error cases could include that its an HTTP/1 message, that the client disabled server push, and the like.
  • The Pusher would have an async fn push_request(&mut self, req: http::Request<()>) -> hyper::Result<()> method that tries to send the PUSH_PROMISE frame to the client. Error cases could include that the request isn't a legal PUSH_PROMISE, that the clients max concurrent streams limit has been reached, the stream has closed, and the like.
  • Once a push promise has been sent to the client, the same http::Request shall be passed to Service::call, and that future spawned in a new task, to generate the response for the PUSH_PROMISE.

An example using this proposal looks like this:

async fn handle(mut req: Request<Body>) -> Result<Response<Body>, E> {
    match hyper::push::pusher(&mut req) {
        Ok(mut pusher) => {
            let promise = Request::builder()
                .uri("/app.js")
                .body(())
                .unwrap();
            if let Err(e) = pusher.push_request(promise).await {
                eprintln!("push failed: {}", e);
            }
        },
        Err(e) => eprintln!("http2 pusher unavailable: {}", e),
    }

    Ok(Response::new(index_page_stream()))
}
@seanmonstar seanmonstar changed the title State of HTTP/2 push Add HTTP/2 push support to Server Dec 14, 2019
@djc

This comment has been minimized.

Copy link
Contributor

@djc djc commented Dec 17, 2019

@stammw would the proposed API make sense for HTTP 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.