improvements in HttpResponse.bodyOrNull

This commit is contained in:
InsanusMokrassar 2023-02-10 15:14:03 +06:00
parent ef9b31aee0
commit 95be1a26f2
2 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,10 @@
## 0.16.9 ## 0.16.9
* `Ktor`:
* `Client`
* `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null
## 0.16.8 ## 0.16.8
* `Versions`: * `Versions`:

View File

@ -4,6 +4,6 @@ import io.ktor.client.call.body
import io.ktor.client.statement.HttpResponse import io.ktor.client.statement.HttpResponse
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull() = takeIf { suspend inline fun <reified T : Any> HttpResponse.bodyOrNull(
status == HttpStatusCode.OK statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK }
} ?.body<T>() ) = takeIf(statusFilter) ?.body<T>()