Skip to content

Commit

Permalink
Finagle
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jan 21, 2025
1 parent 44a8358 commit 3845329
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,17 @@ class FinagleBackend(client: Option[Client] = None) extends Backend[TFuture] {
case _ => Http.client
}
}

val limitedClient =
request.maxResponseBodyLength.fold(client)(l => client.withMaxResponseSize(util.StorageUnit.fromBytes(l)))

val timeout = request.options.readTimeout
if (timeout.isFinite) {
client
limitedClient
.withRequestTimeout(Duration.fromMilliseconds(timeout.toMillis))
.newService(uriToFinagleDestination(request.uri))
} else {
client
limitedClient
.withRequestTimeout(Duration.Top) // Finagle counterpart of Duration.Inf as far as I understand
.newService(uriToFinagleDestination(request.uri))
}
Expand All @@ -239,6 +243,8 @@ class FinagleBackend(client: Option[Client] = None) extends Backend[TFuture] {
case e: com.twitter.finagle.ChannelClosedException => Some(new SttpClientException.ReadException(request, e))
case e: com.twitter.finagle.IndividualRequestTimeoutException =>
Some(new SttpClientException.TimeoutException(request, e))
case e: com.twitter.finagle.http.TooLongMessageException =>
Some(new SttpClientException.ReadException(request, e))
case e: Exception => SttpClientException.defaultExceptionToSttpClientException(request, e)
}
}
Expand Down

0 comments on commit 3845329

Please sign in to comment.