new extension HttpResponse.bodyOrNullOnNoContent

This commit is contained in:
InsanusMokrassar 2023-02-10 15:17:08 +06:00
parent 95be1a26f2
commit a9f7fd8e32
2 changed files with 5 additions and 0 deletions

View File

@ -5,6 +5,7 @@
* `Ktor`: * `Ktor`:
* `Client` * `Client`
* `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null * `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null
* New extension `HttpResponse.bodyOrNullOnNoContent`
## 0.16.8 ## 0.16.8

View File

@ -7,3 +7,7 @@ import io.ktor.http.HttpStatusCode
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull( suspend inline fun <reified T : Any> HttpResponse.bodyOrNull(
statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK } statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK }
) = takeIf(statusFilter) ?.body<T>() ) = takeIf(statusFilter) ?.body<T>()
suspend inline fun <reified T : Any> HttpResponse.bodyOrNullOnNoContent() = bodyOrNull<T> {
it.status != HttpStatusCode.NoContent
}