sttp icon indicating copy to clipboard operation
sttp copied to clipboard

[BUG] HEAD request times out using Http4s backend

Open max-peroch opened this issue 1 year ago • 0 comments

Hello,

I ran into some weirdness that I think is a bug, not sure if the issue lies with Sttp or Htt4s... or if I'm doing something wrong?

I want to perform a simple http HEAD request, which takes no time using async-http-client-backend-fs2 but throws a time out exception after 45s using http4s-backend / http4s-ember-client. And a GET request takes about 8 seconds 🤔

I'm using: - "org.http4s" %% "http4s-ember-client" % "0.23.24" - "com.softwaremill.sttp.client4" %% "http4s-backend" % "4.0.0-M7" - "com.softwaremill.sttp.client4" %% "async-http-client-backend-fs2" % "4.0.0-M7"

Here is a reproduction example:

import cats.effect.{ExitCode, IO, IOApp, Resource}
import org.asynchttpclient.DefaultAsyncHttpClientConfig
import org.http4s.ember.client.EmberClientBuilder
import sttp.capabilities.fs2.Fs2Streams
import sttp.client4.asynchttpclient.fs2.AsyncHttpClientFs2Backend
import sttp.client4.http4s.Http4sBackend
import sttp.client4.{StreamBackend, UriContext, basicRequest}
import sttp.model.HeaderNames

object Main extends IOApp {
  override def run(args: List[String]): IO[ExitCode] = {

    // Works
    //    val ioBackendResource: Resource[IO, StreamBackend[IO, Fs2Streams[IO]]] =
    //      AsyncHttpClientFs2Backend.resourceUsingConfig(new DefaultAsyncHttpClientConfig.Builder().build())

    // Times out after 45s
    val ioBackendResource = Http4sBackend.usingEmberClientBuilder[IO](
      EmberClientBuilder.default[IO]
    )

    ioBackendResource.use { backend =>
      val request = "https://jsoncompare.org/LearningContainer/SampleFiles/Video/MP4/Sample-Video-File-For-Testing.mp4"
      basicRequest.head(uri"$request")
        .send(backend).map { response =>
          response.header(HeaderNames.ContentLength).foreach(length => println(length))
          ExitCode.Success
        }
    }
  }
}

Any idea what might be going on?

Thank you!

Max

max-peroch avatar Dec 01 '23 17:12 max-peroch