new extension HttpResponse.bodyOrNullOnNoContent

This commit is contained in:
InsanusMokrassar committed 2023-02-10 15:17:08 +06:00
1 parent 95be1a26f2
commit a9f7fd8e32
2 files changed
+5

No files matched your search

+1
View File
@@ -5,6 +5,7 @@
* `Ktor`:
* `Client`
* `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null
* New extension `HttpResponse.bodyOrNullOnNoContent`
## 0.16.8
@@ -7,3 +7,7 @@ import io.ktor.http.HttpStatusCode
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull(
statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK }
) = takeIf(statusFilter) ?.body<T>()
suspend inline fun <reified T : Any> HttpResponse.bodyOrNullOnNoContent() = bodyOrNull<T> {
it.status != HttpStatusCode.NoContent
}