diff --git a/CHANGELOG.md b/CHANGELOG.md index 4388c09b9ac..f104a5c4759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.16.9 +* `Ktor`: + * `Client` + * `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null + ## 0.16.8 * `Versions`: diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt index 55abf3b7c87..251d5ab3703 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt @@ -4,6 +4,6 @@ import io.ktor.client.call.body import io.ktor.client.statement.HttpResponse import io.ktor.http.HttpStatusCode -suspend inline fun HttpResponse.bodyOrNull() = takeIf { - status == HttpStatusCode.OK -} ?.body() +suspend inline fun HttpResponse.bodyOrNull( + statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK } +) = takeIf(statusFilter) ?.body()