http4s / http4s-servlet

http4s-servlet support
Apache License 2.0
6 stars 5 forks source link

Http/2 Push Promise support - Jetty backend #8

Open etspaceman opened 3 years ago

etspaceman commented 3 years ago

Jetty supports Push Promises today for Http2 servers. I was in need of this for a project of my own but it doesn't seem that the current Jetty backend supports this today. Created per a conversation w/ @ChristopherDavenport .

rossabaker commented 3 years ago

To make this happen, I think we'd need to understand how they're implemented via a servlet model, and then consider an abstraction that would also fit nicely with forthcoming Ember support. Vault attributes are probably the answer here.

ScalaWilliam commented 3 years ago

Just putting this here: https://github.com/fstab/http2-examples/blob/master/jetty-http2-echo-server/src/main/java/de/consol/labs/h2c/PushEchoServlet.java

rossabaker commented 3 years ago

Interesting. Looks like this delegates to Jetty APIs, rather than being a raw servlet solution. That's probably fine, but has impacts on where it lives if we build on it.

rossabaker commented 3 years ago

I also thought these APIs would be part of Servlet 4/5. I need to make time to read those. The difference between 4 and 5 is the package namespace, but I thought this was a new feature.

ChristopherDavenport commented 2 years ago

To be clear, this is the api I decided on for Embers h2 push promise support.

https://github.com/http4s/http4s/blob/series/0.23/ember-core/shared/src/main/scala/org/http4s/ember/core/h2/H2Keys.scala#L28-L29 - This attaches to a response to push requests out at the same time.

Then in the client, https://github.com/http4s/http4s/blob/series/0.23/ember-client/shared/src/main/scala/org/http4s/ember/client/EmberClientBuilder.scala#L214

It may not be ideal. But its something to work from as a baseline for design.

etspaceman commented 2 years ago

Ok - that looks like interesting progress for clients. Do you have any thoughts on server support for this?

ChristopherDavenport commented 2 years ago

Ember Server Supports this using that H2Key list there.

So Basically

Response[F](Status.Ok)
  .withAttribute(H2Keys.PushPromises, Request[Pure](Method.GET, uri"/foo") :: Nil)

The server then returns that request as a push promise frame, and the server runs that request against its internal routes to generate a response to send normally to the push promises stream identifier.