Skip to content

Instantly share code, notes, and snippets.

@Baccata
Last active June 9, 2023 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Baccata/f29f5154b2628b047dd4d41b5c7725bc to your computer and use it in GitHub Desktop.
Save Baccata/f29f5154b2628b047dd4d41b5c7725bc to your computer and use it in GitHub Desktop.
Reproduction of a http/2 specific problem with http4s-ember-server
//> using lib "org.http4s::http4s-ember-server:0.23.19"
//> using lib "org.http4s::http4s-dsl:0.23.19"
package foo
import cats.effect._
import cats.syntax.all._
import org.http4s.implicits._
import org.http4s.ember.server._
import org.http4s._
import org.http4s.dsl.io._
import org.http4s.dsl.request
object Main extends IOApp.Simple {
// this works (http2 request w/o body):
// curl --http2 localhost:8080/hello
// this works (http1 request w/ body):
// curl -X POST -d foo localhost:8080/text
// this doesn't (http2 request w/ body, server hangs)
// curl --http2 -X POST -d foo localhost:8080/text
//
// Additionally, impossible to exit the application with a ctrl-c as soon
// as ANY request has been sent to the server (whether we hit the first path or not)
val app = HttpApp[IO] {
case GET -> Root / "hello" => Ok("hello")
case request @ POST -> Root / "text" => request.as[String].flatMap(Ok(_))
case request => NotFound()
}
def run: IO[Unit] = EmberServerBuilder
.default[IO]
.withHttp2
.withHttpApp(app)
.build
.useForever
.void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment