Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into linuxArm64
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmedeiros committed Jun 26, 2023
2 parents 14f2fd8 + cbf747e commit 05fda8c
Show file tree
Hide file tree
Showing 109 changed files with 665 additions and 310 deletions.
23 changes: 16 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=4
max_line_length=120
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
max_line_length = 120

[*.json]
indent_size=2
indent_size = 2

[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_filename = disabled
ktlint_standard_class-naming = disabled
ktlint_standard_annotation = disabled
ktlint_standard_comment-wrapping = disabled
12 changes: 7 additions & 5 deletions buildSrc/src/main/kotlin/Codestyle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import org.gradle.api.*
import org.gradle.api.tasks.*
import org.gradle.kotlin.dsl.*
import org.jmailen.gradle.kotlinter.tasks.*

fun Project.configureCodestyle() {
apply(plugin = "org.jmailen.kotlinter")

kotlinter.apply {
ignoreFailures = true
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
disabledRules = arrayOf(
"no-wildcard-imports",
"indent"
)
}

val editorconfigFile = rootProject.file(".editorconfig")
tasks.withType<LintTask> {
inputs.file(editorconfigFile).withPathSensitivity(PathSensitivity.RELATIVE)
}
}
14 changes: 14 additions & 0 deletions buildSrc/src/main/kotlin/test/server/tests/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.plugins.cachingheaders.*
import io.ktor.server.plugins.conditionalheaders.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.date.*
Expand Down Expand Up @@ -55,6 +56,19 @@ internal fun Application.cacheTestServer() {
call.respondText(current.toString())
}

get("/etag-304") {
if (call.request.header("If-None-Match") == "My-ETAG") {
call.response.header("Etag", "My-ETAG")
call.response.header("Vary", "Origin")
call.respond(HttpStatusCode.NotModified)
return@get
}

call.response.header("Etag", "My-ETAG")
call.response.header("Vary", "Origin, Accept-Encoding")
call.respondText(contentType = ContentType.Application.Json) { "{}" }
}

get("/last-modified") {
val current = counter.incrementAndGet()
val response = TextContent("$current", ContentType.Text.Plain)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ktor.ide.jvmAndCommonOnly=false
kotlin.code.style=official

# config
version=2.3.1
version=2.3.2-SNAPSHOT

# gradle
org.gradle.daemon=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coroutines-version = "1.7.1"
atomicfu-version = "0.20.2"
serialization-version = "1.5.1"
validator-version = "0.8.0"
ktlint-version = "3.10.0"
ktlint-version = "3.15.0"

netty-version = "4.1.92.Final"
netty-tcnative-version = "2.0.61.Final"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.http.client.methods.*
import org.apache.http.client.utils.*
import org.apache.http.entity.*
import org.apache.http.nio.*
import org.apache.http.nio.ContentEncoder
import org.apache.http.nio.protocol.*
import org.apache.http.protocol.*
import java.nio.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ internal fun ApacheRequestProducer(

return BasicRequestProducer(
setupRequest(requestData, config),
if (!hasContent && isGetOrHead) null
else ApacheRequestEntityProducer(requestData, callContext, contentLength, type, isChunked)
if (!hasContent && isGetOrHead) {
null
} else {
ApacheRequestEntityProducer(requestData, callContext, contentLength, type, isChunked)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public suspend fun HttpClient.webSocketRawSession(
val sessionCompleted = CompletableDeferred<Unit>()
result.complete(session)
session.outgoing.invokeOnClose {
if (it != null) sessionCompleted.completeExceptionally(it)
else sessionCompleted.complete(Unit)
if (it != null) {
sessionCompleted.completeExceptionally(it)
} else sessionCompleted.complete(Unit)
}
sessionCompleted.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ public class HttpRequestRetry internal constructor(configuration: Configuration)
val subRequest = HttpRequestBuilder().takeFrom(request)
request.executionContext.invokeOnCompletion { cause ->
val subRequestJob = subRequest.executionContext as CompletableJob
if (cause == null) subRequestJob.complete()
else subRequestJob.completeExceptionally(cause)
if (cause == null) {
subRequestJob.complete()
} else subRequestJob.completeExceptionally(cause)
}
return subRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ internal object ResponseHook :
}

internal object TransformRequestBodyHook :
ClientHook<suspend TransformRequestBodyContext.(
request: HttpRequestBuilder,
content: Any,
bodyType: TypeInfo?
) -> OutgoingContent?> {
ClientHook<
suspend TransformRequestBodyContext.(
request: HttpRequestBuilder,
content: Any,
bodyType: TypeInfo?
) -> OutgoingContent?
> {

override fun install(
client: HttpClient,
Expand All @@ -84,11 +86,13 @@ internal object TransformRequestBodyHook :
}

internal object TransformResponseBodyHook :
ClientHook<suspend TransformResponseBodyContext.(
response: HttpResponse,
content: ByteReadChannel,
requestedType: TypeInfo
) -> Any?> {
ClientHook<
suspend TransformResponseBodyContext.(
response: HttpResponse,
content: ByteReadChannel,
requestedType: TypeInfo
) -> Any?
> {

override fun install(
client: HttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ internal class UnlimitedCacheStorage : HttpCacheStorage() {

override fun find(url: Url, varyKeys: Map<String, String>): HttpCacheEntry? {
val data = store.computeIfAbsent(url) { ConcurrentSet() }
return data.find { it.varyKeys == varyKeys }
return data.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
}
}

override fun findByUrl(url: Url): Set<HttpCacheEntry> = store[url] ?: emptySet()
Expand All @@ -42,7 +44,9 @@ internal class UnlimitedStorage : CacheStorage {

override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
val data = store.computeIfAbsent(url) { ConcurrentSet() }
return data.find { it.varyKeys == varyKeys }
return data.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
}
}

override suspend fun findAll(url: Url): Set<CachedResponseData> = store[url] ?: emptySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ internal fun Cookie.matches(requestUrl: Url): Boolean {
if (path != "/" &&
requestPath != path &&
!requestPath.startsWith(path)
) return false
) {
return false
}

return !(secure && !requestUrl.protocol.isSecure())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public class WebSockets internal constructor(

val negotiated = if (extensionsSupported) {
plugin.completeNegotiation(context)
} else emptyList()
} else {
emptyList()
}

clientSession.apply {
start(negotiated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public suspend fun HttpClient.webSocketSession(
val sessionCompleted = CompletableDeferred<Unit>()
sessionDeferred.complete(session)
session.outgoing.invokeOnClose {
if (it != null) sessionCompleted.completeExceptionally(it)
else sessionCompleted.complete(Unit)
if (it != null) {
sessionCompleted.completeExceptionally(it)
} else sessionCompleted.complete(Unit)
}
sessionCompleted.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class HttpRequestBuilder : HttpMessageBuilder {
*/
public var bodyType: TypeInfo?
get() = attributes.getOrNull(BodyTypeAttributeKey)

@InternalAPI set(value) {
if (value != null) {
attributes.put(BodyTypeAttributeKey, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class CacheExpiresTest {
get() = error("Shouldn't be used")
override val responseTime: GMTDate
get() = error("Shouldn't be used")

@OptIn(InternalAPI::class)
override val content: ByteReadChannel
get() = error("Shouldn't be used")
Expand Down
16 changes: 8 additions & 8 deletions ktor-client/ktor-client-core/common/test/ClientPluginsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class ClientPluginsTest {
fun testCustomHook() = testSuspend {
var hookCalled = false
val plugin = createClientPlugin("F") {
on(CustomHook) {
hookCalled = true
}
on(CustomHook) {
hookCalled = true
}
}

val client = HttpClient(MockEngine) {
Expand All @@ -166,11 +166,11 @@ class ClientPluginsTest {
@Test
fun testSendHook() = testSuspend {
val plugin = createClientPlugin("F") {
on(Send) {
val call = proceed(it)
assertEquals("temp response", call.response.bodyAsText())
proceed(it)
}
on(Send) {
val call = proceed(it)
assertEquals("temp response", call.response.bodyAsText())
proceed(it)
}
}

val client = HttpClient(MockEngine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ internal class CachingCacheStorage(
store[url] = delegate.findAll(url)
}
val data = store.getValue(url)
return data.find { it.varyKeys == varyKeys }
return data.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
}
}

override suspend fun findAll(url: Url): Set<CachedResponseData> {
Expand Down Expand Up @@ -76,7 +78,10 @@ private class FileCacheStorage(
}

override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
return readCache(key(url)).find { it.varyKeys == varyKeys }
val data = readCache(key(url))
return data.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
}
}

private fun key(url: Url) = hex(MessageDigest.getInstance("MD5").digest(url.toString().encodeToByteArray()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ private class InMemoryCacheStorage : CacheStorage {
override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
findCalledCount++
val cache = store.computeIfAbsent(url) { mutableSetOf() }
return cache.find { it.varyKeys == varyKeys }
return cache.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
}
}

override suspend fun findAll(url: Url): Set<CachedResponseData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ internal class CurlMultiApiHandler : Closeable {

private val cancelledHandles = mutableSetOf<Pair<EasyHandle, Throwable>>()

@Suppress("DEPRECATION")
private val multiHandle: MultiHandle = curl_multi_init()
?: @Suppress("DEPRECATION") throw CurlRuntimeException("Could not initialize curl multi handle")
?: throw CurlRuntimeException("Could not initialize curl multi handle")

private val easyHandlesToUnpauseLock = SynchronizedObject()
private val easyHandlesToUnpause = mutableListOf<EasyHandle>()
Expand All @@ -47,7 +48,9 @@ internal class CurlMultiApiHandler : Closeable {

fun scheduleRequest(request: CurlRequestData, deferred: CompletableDeferred<CurlSuccess>): EasyHandle {
val easyHandle = curl_easy_init()
?: throw @Suppress("DEPRECATION") CurlIllegalStateException("Could not initialize an easy handle")
?: throw
@Suppress("DEPRECATION")
CurlIllegalStateException("Could not initialize an easy handle")

val bodyStartedReceiving = CompletableDeferred<Unit>()
val responseData = CurlResponseBuilder(request)
Expand Down Expand Up @@ -207,9 +210,9 @@ internal class CurlMultiApiHandler : Closeable {
val messagePtr = curl_multi_info_read(multiHandle, messagesLeft.ptr)
val message = messagePtr?.pointed ?: continue

@Suppress("DEPRECATION")
val easyHandle = message.easy_handle
?: @Suppress("DEPRECATION")
throw CurlIllegalStateException("Got a null easy handle from the message")
?: throw CurlIllegalStateException("Got a null easy handle from the message")

try {
val result = processCompletedEasyHandle(message.msg, easyHandle, message.data.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ internal class DarwinWebsocketSession(
FrameType.TEXT -> {
suspendCancellableCoroutine<Unit> { continuation ->
task.sendMessage(NSURLSessionWebSocketMessage(String(frame.data))) { error ->
if (error == null) continuation.resume(Unit)
else continuation.resumeWithException(DarwinHttpRequestException(error))
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}

FrameType.BINARY -> {
suspendCancellableCoroutine<Unit> { continuation ->
task.sendMessage(NSURLSessionWebSocketMessage(frame.data.toNSData())) { error ->
if (error == null) continuation.resume(Unit)
else continuation.resumeWithException(DarwinHttpRequestException(error))
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}
Expand Down
Loading

0 comments on commit 05fda8c

Please sign in to comment.