Skip to content

Commit 61e9c01

Browse files
committed
Fixes after update to v5.4
1 parent c2a1a6e commit 61e9c01

File tree

4 files changed

+56
-26
lines changed

4 files changed

+56
-26
lines changed

ktor-client/ktor-client-apache5/api/ktor-client-apache5.api

+2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ public final class io/ktor/client/engine/apache5/Apache5EngineConfig : io/ktor/c
1515
public final fun getFollowRedirects ()Z
1616
public final fun getSocketTimeout ()I
1717
public final fun getSslContext ()Ljavax/net/ssl/SSLContext;
18+
public final fun getSslHostnameVerificationPolicy ()Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;
1819
public final fun setConnectTimeout (J)V
1920
public final fun setConnectionRequestTimeout (J)V
2021
public final fun setFollowRedirects (Z)V
2122
public final fun setSocketTimeout (I)V
2223
public final fun setSslContext (Ljavax/net/ssl/SSLContext;)V
24+
public final fun setSslHostnameVerificationPolicy (Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;)V
2325
}
2426

2527
public final class io/ktor/client/engine/apache5/Apache5EngineContainer : io/ktor/client/HttpClientEngineContainer {

ktor-client/ktor-client-apache5/jvm/src/io/ktor/client/engine/apache5/Apache5Engine.kt

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package io.ktor.client.engine.apache5
@@ -9,19 +9,22 @@ import io.ktor.client.plugins.*
99
import io.ktor.client.plugins.sse.*
1010
import io.ktor.client.request.*
1111
import io.ktor.utils.io.*
12-
import kotlinx.coroutines.*
13-
import org.apache.hc.client5.http.config.*
14-
import org.apache.hc.client5.http.impl.async.*
15-
import org.apache.hc.client5.http.impl.nio.*
16-
import org.apache.hc.client5.http.ssl.*
17-
import org.apache.hc.core5.http.*
18-
import org.apache.hc.core5.http.ssl.*
19-
import org.apache.hc.core5.io.*
20-
import org.apache.hc.core5.reactor.*
21-
import org.apache.hc.core5.ssl.*
22-
import org.apache.hc.core5.util.*
23-
import java.net.*
24-
import java.util.concurrent.*
12+
import kotlinx.coroutines.Job
13+
import org.apache.hc.client5.http.config.ConnectionConfig
14+
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient
15+
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder
16+
import org.apache.hc.client5.http.impl.async.HttpAsyncClients
17+
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder
18+
import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder
19+
import org.apache.hc.core5.http.HttpHost
20+
import org.apache.hc.core5.http.ssl.TLS
21+
import org.apache.hc.core5.io.CloseMode
22+
import org.apache.hc.core5.reactor.IOReactorConfig
23+
import org.apache.hc.core5.ssl.SSLContexts
24+
import org.apache.hc.core5.util.Timeout
25+
import java.net.InetSocketAddress
26+
import java.net.Proxy
27+
import java.util.concurrent.TimeUnit
2528

2629
private const val MAX_CONNECTIONS_COUNT = 1000
2730
private const val IO_THREAD_COUNT_DEFAULT = 4
@@ -89,6 +92,10 @@ internal class Apache5Engine(override val config: Apache5EngineConfig) : HttpCli
8992
ClientTlsStrategyBuilder.create()
9093
.setSslContext(config.sslContext ?: SSLContexts.createSystemDefault())
9194
.setTlsVersions(TLS.V_1_3, TLS.V_1_2)
95+
// TODO: Uncomment this line and remove apply after update to v5.5
96+
// https://github.com/apache/httpcomponents-client/commit/001eff70646c982c8c4a7c8a385d92f42579f2b5
97+
// .setHostVerificationPolicy(config.sslHostnameVerificationPolicy)
98+
.apply { setHostnameVerificationPolicy(config.sslHostnameVerificationPolicy) }
9299
.build()
93100
)
94101
.setDefaultConnectionConfig(

ktor-client/ktor-client-apache5/jvm/src/io/ktor/client/engine/apache5/Apache5EngineConfig.kt

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package io.ktor.client.engine.apache5
66

77
import io.ktor.client.engine.*
88
import org.apache.hc.client5.http.config.RequestConfig
99
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder
10+
import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy
1011
import javax.net.ssl.SSLContext
1112

1213
/**
@@ -47,6 +48,21 @@ public class Apache5EngineConfig : HttpClientEngineConfig() {
4748
*/
4849
public var sslContext: SSLContext? = null
4950

51+
/**
52+
* Specifies the policy for verifying hostnames during SSL/TLS connections.
53+
*
54+
* The policy determines when hostname verification occurs during the connection process:
55+
* - During TLS handshake (by JSSE)
56+
* - After TLS handshake (by HttpClient)
57+
* - Or both (default)
58+
*
59+
* Default value is [HostnameVerificationPolicy.BOTH] which provides maximum security
60+
* by performing verification at both stages.
61+
*
62+
* @see HostnameVerificationPolicy
63+
*/
64+
public var sslHostnameVerificationPolicy: HostnameVerificationPolicy = HostnameVerificationPolicy.BOTH
65+
5066
internal var customRequest: (RequestConfig.Builder.() -> RequestConfig.Builder) = { this }
5167

5268
internal var customClient: (HttpAsyncClientBuilder.() -> HttpAsyncClientBuilder) = { this }

ktor-client/ktor-client-apache5/jvm/src/io/ktor/client/engine/apache5/ApacheResponseConsumer.kt

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
/*
2-
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package io.ktor.client.engine.apache5
66

77
import io.ktor.client.request.*
88
import io.ktor.util.*
99
import io.ktor.utils.io.*
10-
import kotlinx.atomicfu.*
10+
import kotlinx.atomicfu.atomic
1111
import kotlinx.coroutines.*
12-
import kotlinx.coroutines.channels.*
12+
import kotlinx.coroutines.channels.Channel
1313
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
14-
import org.apache.hc.core5.concurrent.*
15-
import org.apache.hc.core5.http.*
16-
import org.apache.hc.core5.http.nio.*
17-
import org.apache.hc.core5.http.protocol.*
18-
import java.nio.*
19-
import kotlin.coroutines.*
14+
import org.apache.hc.core5.concurrent.CallbackContribution
15+
import org.apache.hc.core5.concurrent.FutureCallback
16+
import org.apache.hc.core5.http.EntityDetails
17+
import org.apache.hc.core5.http.Header
18+
import org.apache.hc.core5.http.HttpResponse
19+
import org.apache.hc.core5.http.nio.AsyncEntityConsumer
20+
import org.apache.hc.core5.http.nio.AsyncResponseConsumer
21+
import org.apache.hc.core5.http.nio.CapacityChannel
22+
import org.apache.hc.core5.http.protocol.HttpContext
23+
import java.nio.ByteBuffer
24+
import kotlin.coroutines.CoroutineContext
2025

2126
private object CloseChannel
2227

@@ -28,8 +33,8 @@ internal class BasicResponseConsumer(private val dataConsumer: ApacheResponseCon
2833
override fun consumeResponse(
2934
response: HttpResponse,
3035
entityDetails: EntityDetails?,
31-
httpContext: HttpContext,
32-
resultCallback: FutureCallback<Unit>
36+
context: HttpContext?,
37+
resultCallback: FutureCallback<Unit>,
3338
) {
3439
responseDeferred.complete(response)
3540
if (entityDetails != null) {

0 commit comments

Comments
 (0)