Skip to content

Commit

Permalink
Armeria
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jan 21, 2025
1 parent 1a20bec commit 56e18bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import sttp.model._
import sttp.monad.syntax._
import sttp.monad.{Canceler, MonadAsyncError}
import sttp.client4.compression.Compressor
import com.linecorp.armeria.common.ContentTooLargeException

abstract class AbstractArmeriaBackend[F[_], S <: Streams[S]](
client: WebClient = WebClient.of(),
Expand Down Expand Up @@ -122,7 +123,7 @@ abstract class AbstractArmeriaBackend[F[_], S <: Streams[S]](

val contentType = customContentType.getOrElse(ArmeriaMediaType.parse(request.body.defaultContentType.toString()))

body match {
val withBody = body match {
case NoBody => requestPreparation
case StringBody(s, encoding, _) =>
val charset =
Expand All @@ -149,6 +150,8 @@ abstract class AbstractArmeriaBackend[F[_], S <: Streams[S]](
case StreamBody(s) =>
requestPreparation.content(contentType, streamToPublisher(s.asInstanceOf[streams.BinaryStream]))
}

request.maxResponseBodyLength.fold(withBody)(l => withBody.maxResponseLength(l))
}

private def methodToArmeria(method: Method): HttpMethod =
Expand Down Expand Up @@ -203,10 +206,9 @@ abstract class AbstractArmeriaBackend[F[_], S <: Streams[S]](
case ex: UnprocessedRequestException =>
// The cause of an UnprocessedRequestException is always not null
Some(new ConnectException(request, ex.getCause.asInstanceOf[Exception]))
case ex: ResponseTimeoutException =>
Some(new TimeoutException(request, ex))
case ex: ClosedStreamException =>
Some(new ReadException(request, ex))
case ex: ResponseTimeoutException => Some(new TimeoutException(request, ex))
case ex: ClosedStreamException => Some(new ReadException(request, ex))
case ex: ContentTooLargeException => Some(new ReadException(request, ex))
case ex =>
SttpClientException.defaultExceptionToSttpClientException(request, ex)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/responses/body.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ If you'd like to use additional decompression algorithms, you'll need to:

To limit the size of the response body, use the `maxResponseBodyLength` method on the request description. This modified the `RequestOption`s associated with the request. By default, there's no limit set.

When a limit is set and it is exceed, sending the request will fail with a `SttpClientException.ReadException`, with the cause being `StreamMaxLengthExceededException`.
When a limit is set and it is exceed, sending the request will fail with a `SttpClientException.ReadException`.

0 comments on commit 56e18bd

Please sign in to comment.