diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1baf3979a..4eba7d2512f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.12.8 + +* `Versions`: + * `Ktor`: `2.1.0` -> `2.1.1` + * `Compose`: `1.2.0-alpha01-dev764` -> `1.2.0-alpha01-dev774` +* `Ktor`: + * `Client`: + * New extension `HttpClient#bodyOrNull` which returns `null` in case when server responded with `No Content` (204) + * `Server`: + * New extension `ApplicationCall#respondOrNoContent` which responds `No Content` (204) when passed data is null + ## 0.12.7 * `Repos`: diff --git a/gradle.properties b/gradle.properties index 22ec9736793..b3d2f587601 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.12.7 -android_code_version=146 +version=0.12.8 +android_code_version=147 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bb591d74a26..ddb4c3d7d0b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,14 +4,14 @@ kt = "1.7.10" kt-serialization = "1.4.0" kt-coroutines = "1.6.4" -jb-compose = "1.2.0-alpha01-dev764" +jb-compose = "1.2.0-alpha01-dev774" jb-exposed = "0.39.2" jb-dokka = "1.7.10" klock = "3.0.0" uuid = "0.5.0" -ktor = "2.1.0" +ktor = "2.1.1" gh-release = "2.4.1" 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 new file mode 100644 index 00000000000..55abf3b7c87 --- /dev/null +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt @@ -0,0 +1,9 @@ +package dev.inmo.micro_utils.ktor.client + +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() diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/RespondOrNoContent.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/RespondOrNoContent.kt new file mode 100644 index 00000000000..3bc770d1ede --- /dev/null +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/RespondOrNoContent.kt @@ -0,0 +1,15 @@ +package dev.inmo.micro_utils.ktor.server + +import io.ktor.http.HttpStatusCode +import io.ktor.server.application.ApplicationCall +import io.ktor.server.response.respond + +suspend inline fun ApplicationCall.respondOrNoContent( + data: T? +) { + if (data == null) { + respond(HttpStatusCode.NoContent) + } else { + respond(data) + } +}