yannisf
yannisf

Reputation: 6136

Set Finatra HTTP request timeout

Is it possible to set HTTP request-response timeout in a Finatra server?

The http controller callback typically returns a Future, that once resolved the response is transmitted. I would like to define, within Finatra, how long the server should wait before returning a 500 or 400 response.

Upvotes: 0

Views: 310

Answers (2)

user3237183
user3237183

Reputation:

You can extend the HttpServer and define your own timeout

    trait CustomServer extends HttpServer with Tls {

then you overwrite the configureHttpServer method and you define timeout, requests sites, and other attributes

  override def configureHttpServer(server: Http.Server): Http.Server = {
    server.withAdmissionControl.concurrencyLimit(maxConcurrentRequests = 2000, maxWaiters = 0)
      .withResponseClassifier(HttpResponseClassifier.ServerErrorsAsFailures)
      .withMaxRequestSize(StorageUnit.fromMegabytes(200))
      .withRequestTimeout(50.seconds)
  }

Or, a more minimal example in your class that extends Http.Server:

      override protected def configureHttpServer(server: Http.Server): Http.Server = {
        super.configureHttpServer(server.withRequestTimeout(50.seconds))
      }

Upvotes: 1

Dima
Dima

Reputation: 40508

I think, you are looking for Future.within

Upvotes: 0

Related Questions