Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ktor.version from 2.3.12 to 3.0.1 #1949

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -76,7 +66,7 @@ internal class LogbookClientWithSinkTest {

@Test
fun `Should log request and response`() {
val response = sendAndReceive() {
val response = sendAndReceive {
body = "ping"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion logbook-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<jackson.version>2.18.0</jackson.version>
<json-path.version>2.9.0</json-path.version>
<kotlin.version>2.0.21</kotlin.version>
<ktor.version>2.3.12</ktor.version>
<ktor.version>3.0.1</ktor.version>
<netty.version>4.1.114.Final</netty.version>
<reactor-netty.version>1.1.23</reactor-netty.version>
<slf4j.version>2.0.16</slf4j.version>
Expand Down
Loading