softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.46k stars 309 forks source link

Add support for customizing responses in backends #701

Closed pewniak747 closed 3 years ago

pewniak747 commented 4 years ago

Most of sttp' backends accept a customizeRequest function, which allows the user to modify the request prior to sending. For example, in AkkaHttpBackend:

https://github.com/softwaremill/sttp/blob/a29516923b59f0b06d75f5670f25aa9b2803ea8a/akka-http-backend/src/main/scala/sttp/client/akkahttp/AkkaHttpBackend.scala#L395

I propose to add support for customizeResponse function, which would do the similar thing for responses - modify the response prior to further processing.

In AkkaHttpBackend, it could look like this:

      customizeResponse: (HttpRequest, HttpResponse) => HttpResponse,

My original motivation for this is to be able to call response.mapEntity(_.withoutSizeLimit) on certain akka-http responses.

adamw commented 3 years ago

Implemented for Akka, where it makes sense. I don't think there are use-cases for other implementations, but if so, please reopen the issue.