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

Be able to create an AsyncHttpClient with a custom request timeout #3606

Closed
henricook opened this issue Jul 28, 2020 · 3 comments
Closed

Be able to create an AsyncHttpClient with a custom request timeout #3606

henricook opened this issue Jul 28, 2020 · 3 comments
Labels
enhancement Feature requests and improvements good first issue A tractable issue for those looking to make an initial contribution

Comments

@henricook
Copy link

henricook commented Jul 28, 2020

I mentioned this briefly on Gitter and it was suggested I raise an issue.

I want to be able to create an AsyncHttpClient with a custom request timeout. At the moment I can use AsyncHttpClient.resource[Task]() to get the defaultConfig from http4s AsyncHttpClient. I might have missed something (please tell me if I have!) but I don't think I can tweak this to give me a custom request timeout.

defaultConfig is:

  val defaultConfig = new DefaultAsyncHttpClientConfig.Builder()
    .setMaxConnectionsPerHost(200)
    .setMaxConnections(400)
    .setRequestTimeout(defaults.RequestTimeout.toMillis.toInt)
    .setThreadFactory(threadFactory(name = { i =>
      s"http4s-async-http-client-worker-${i}"
    }))
    .setCookieStore(new NoOpCookieStore)
    .build()

I tried copying and pasting this into my own code but NoOpCookieStore is a package-private class and threadFactory was recently moved to http4s internals where I can't access it.

So my goal is to have one client with a 30 second timeout in use by my application (e.g. when talking to external services) but I want my acceptance test http4s client to have >30 seconds (e.g. 45 seconds) so it doesn't timeout whilst an external service being tested is timing out.

TL;DR - I just want to be able to set the request timeout for a client

Related:

@hamnis kindly pointed out that this is possible, which gives me an immediate workaround:

 AsyncHttpClient.resource({
      val b = new DefaultAsyncHttpClientConfig.Builder(AsyncHttpClient.defaultConfig)
      b.setRequestTimeout(3000)
      b.build()
    })
@hamnis
Copy link
Contributor

hamnis commented Jul 29, 2020

We could add a function to make this easier.

AsyncHttpClient.configure(fn: DefaultAsyncHttpClientConfig.Builder => DefaultAsyncHttpClientConfig.Builder): HttpClientConfig

@hamnis hamnis added enhancement Feature requests and improvements good first issue A tractable issue for those looking to make an initial contribution labels Jul 29, 2020
@jyoo980
Copy link
Contributor

jyoo980 commented Aug 4, 2020

Could I try my hand at this?

I use Scala at work but it'll be my first foray into Scala open-source.

@hamnis
Copy link
Contributor

hamnis commented Aug 6, 2020

Fixed by #3623

@hamnis hamnis closed this as completed Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and improvements good first issue A tractable issue for those looking to make an initial contribution
Projects
None yet
Development

No branches or pull requests

3 participants