diff --git a/logbook-ktor-client/src/main/kotlin/org/zalando/logbook/client/LogbookClient.kt b/logbook-ktor-client/src/main/kotlin/org/zalando/logbook/client/LogbookClient.kt
index 156f049a0..b70661f83 100644
--- a/logbook-ktor-client/src/main/kotlin/org/zalando/logbook/client/LogbookClient.kt
+++ b/logbook-ktor-client/src/main/kotlin/org/zalando/logbook/client/LogbookClient.kt
@@ -11,8 +11,8 @@ import io.ktor.client.request.HttpSendPipeline
import io.ktor.client.statement.HttpReceivePipeline
import io.ktor.http.content.OutgoingContent
import io.ktor.util.AttributeKey
-import io.ktor.util.InternalAPI
import io.ktor.util.split
+import io.ktor.utils.io.InternalAPI
import io.ktor.utils.io.discard
import kotlinx.coroutines.launch
import org.apiguardian.api.API
@@ -55,7 +55,7 @@ class LogbookClient(
}
scope.receivePipeline.intercept(HttpReceivePipeline.After) { httpResponse ->
- val (loggingContent, responseContent) = httpResponse.content.split(httpResponse)
+ val (loggingContent, responseContent) = httpResponse.rawContent.split(httpResponse)
scope.launch(coroutineContext) {
val responseProcessingStage = httpResponse.call.attributes[responseProcessingStageKey]
val clientResponse = ClientResponse(httpResponse)
diff --git a/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientTest.kt b/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientTest.kt
index bd3e3b0db..64e7936a6 100644
--- a/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientTest.kt
+++ b/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientTest.kt
@@ -6,7 +6,6 @@ import io.ktor.client.call.body
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.post
import io.ktor.http.HttpStatusCode
-import io.ktor.server.application.call
import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer
import io.ktor.server.request.contentType
@@ -15,7 +14,7 @@ import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
-import io.ktor.util.InternalAPI
+import io.ktor.utils.io.InternalAPI
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
@@ -124,7 +123,7 @@ internal class LogbookClientTest {
@Test
fun `Should not log response if inactive`() {
`when`(writer.isActive).thenReturn(false)
- sendAndReceive() {
+ sendAndReceive {
body = "Hello, world!"
}
verify(writer, never()).write(any(Correlation::class.java), any())
diff --git a/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientWithSinkTest.kt b/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientWithSinkTest.kt
index 2113a0ad9..33e816b37 100644
--- a/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientWithSinkTest.kt
+++ b/logbook-ktor-client/src/test/kotlin/org/zalando/logbook/client/LogbookClientWithSinkTest.kt
@@ -1,21 +1,17 @@
package org.zalando.logbook.client
-import io.ktor.server.application.Application
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.post
import io.ktor.http.*
-import io.ktor.server.application.call
+import io.ktor.server.application.Application
import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer
-import io.ktor.server.request.contentType
-import io.ktor.server.request.receiveText
-import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
-import io.ktor.util.InternalAPI
+import io.ktor.utils.io.InternalAPI
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
@@ -24,22 +20,16 @@ import org.junit.jupiter.api.Test
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.mock
-import org.mockito.Mockito.never
import org.mockito.Mockito.timeout
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.zalando.logbook.Correlation
-import org.zalando.logbook.HttpLogWriter
import org.zalando.logbook.HttpRequest
import org.zalando.logbook.HttpResponse
import org.zalando.logbook.Logbook
-import org.zalando.logbook.Precorrelation
import org.zalando.logbook.Sink
import org.zalando.logbook.common.ExperimentalLogbookKtorApi
-import org.zalando.logbook.core.DefaultHttpLogFormatter
-import org.zalando.logbook.core.DefaultSink
import org.zalando.logbook.test.TestStrategy
-import kotlin.math.sin
@ExperimentalLogbookKtorApi
@OptIn(InternalAPI::class)
@@ -76,7 +66,7 @@ internal class LogbookClientWithSinkTest {
@Test
fun `Should log request and response`() {
- val response = sendAndReceive() {
+ val response = sendAndReceive {
body = "ping"
}
diff --git a/logbook-ktor-common/src/main/kotlin/org/zalando/logbook/common/ContentUtils.kt b/logbook-ktor-common/src/main/kotlin/org/zalando/logbook/common/ContentUtils.kt
index bff26b6d3..a3ddc72e6 100644
--- a/logbook-ktor-common/src/main/kotlin/org/zalando/logbook/common/ContentUtils.kt
+++ b/logbook-ktor-common/src/main/kotlin/org/zalando/logbook/common/ContentUtils.kt
@@ -1,8 +1,8 @@
package org.zalando.logbook.common
import io.ktor.http.content.OutgoingContent
-import io.ktor.util.toByteArray
import io.ktor.utils.io.ByteReadChannel
+import io.ktor.utils.io.toByteArray
import io.ktor.utils.io.writer
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.coroutineContext
@@ -17,6 +17,7 @@ suspend fun OutgoingContent.readBytes(scope: CoroutineScope): ByteArray = runCat
is OutgoingContent.ByteArrayContent -> bytes()
is OutgoingContent.ReadChannelContent -> readFrom().readBytes()
is OutgoingContent.WriteChannelContent -> scope.writer(coroutineContext) { writeTo(channel) }.channel.readBytes()
+ is OutgoingContent.ContentWrapper -> delegate().readBytes(scope)
}
}.getOrElse {
EMPTY_BODY
diff --git a/logbook-ktor-common/src/test/kotlin/org/zalando/logbook/ktor/common/ContentUtilsUnitTest.kt b/logbook-ktor-common/src/test/kotlin/org/zalando/logbook/ktor/common/ContentUtilsUnitTest.kt
index 1a8b6b98a..eaa6fee5c 100644
--- a/logbook-ktor-common/src/test/kotlin/org/zalando/logbook/ktor/common/ContentUtilsUnitTest.kt
+++ b/logbook-ktor-common/src/test/kotlin/org/zalando/logbook/ktor/common/ContentUtilsUnitTest.kt
@@ -4,7 +4,6 @@ import io.ktor.content.ByteArrayContent
import io.ktor.http.content.OutgoingContent
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.ByteWriteChannel
-import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.writeFully
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@@ -84,10 +83,23 @@ internal class ContentUtilsUnitTest {
fun `Should return fallback value from ByteReadChannel`() = runBlocking {
val delegate = ByteReadChannel(expected.toByteArray())
val content = object : ByteReadChannel by delegate {
- override suspend fun readRemaining(limit: Long): ByteReadPacket =
+ override suspend fun awaitContent(min: Int): Boolean {
throw IllegalArgumentException()
+ }
}
val bytes = content.readBytes()
assertEquals(EMPTY_BODY, bytes)
}
+
+ @Test
+ fun `Should read ContentWrapper`() = runBlocking {
+ val content = ByteArrayContent(expected.toByteArray())
+ val contentWrapper = object : OutgoingContent.ContentWrapper(content) {
+ override fun copy(delegate: OutgoingContent): ContentWrapper {
+ return this
+ }
+ }
+ val result = contentWrapper.readBytes(scope).toString(UTF_8)
+ assertEquals(expected, result)
+ }
}
diff --git a/logbook-ktor-server/src/test/kotlin/org/zalando/logbook/server/LogbookServerTest.kt b/logbook-ktor-server/src/test/kotlin/org/zalando/logbook/server/LogbookServerTest.kt
index ec35dc418..225cd4bf3 100644
--- a/logbook-ktor-server/src/test/kotlin/org/zalando/logbook/server/LogbookServerTest.kt
+++ b/logbook-ktor-server/src/test/kotlin/org/zalando/logbook/server/LogbookServerTest.kt
@@ -8,7 +8,6 @@ import io.ktor.client.request.post
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
-import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer
@@ -18,7 +17,7 @@ import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
-import io.ktor.util.InternalAPI
+import io.ktor.utils.io.InternalAPI
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
diff --git a/logbook-parent/pom.xml b/logbook-parent/pom.xml
index ff3192273..1e2663825 100644
--- a/logbook-parent/pom.xml
+++ b/logbook-parent/pom.xml
@@ -31,7 +31,7 @@
2.18.1
2.9.0
2.0.21
- 2.3.12
+ 3.0.1
4.1.114.Final
1.1.23
2.0.16