You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/09/24 19:36:11 UTC
(httpcomponents-core) 02/02: HTTPCORE-785: Updated request execution example with Conscrypt as a security provider
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.3.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit f8b1b4aa1ec0e6aca3c34f123e722de9cadf2eda
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Sep 23 21:31:42 2025 +0200
HTTPCORE-785: Updated request execution example with Conscrypt as a security provider
---
.../http2/examples/H2ConscriptRequestExecutionExample.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2ConscriptRequestExecutionExample.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2ConscriptRequestExecutionExample.java
index e33f4e248..1d182e2b8 100644
--- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2ConscriptRequestExecutionExample.java
+++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2ConscriptRequestExecutionExample.java
@@ -26,6 +26,8 @@
*/
package org.apache.hc.core5.http2.examples;
+import java.security.Provider;
+import java.security.Security;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
@@ -43,6 +45,7 @@
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
import org.apache.hc.core5.http.nio.support.AsyncRequestBuilder;
import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.H2StreamListener;
@@ -55,7 +58,7 @@
/**
* This example demonstrates how to execute HTTP/2 requests over TLS connections
- * with Java 1.7 or Java 1.8 and Conscrypt TLS library
+ * with Conscrypt TLS library.
*/
public class H2ConscriptRequestExecutionExample {
@@ -66,13 +69,20 @@ public static void main(final String[] args) throws Exception {
.setPushEnabled(false)
.build();
+ final Provider conscryptProvider = Conscrypt.newProviderBuilder()
+ .provideTrustManager(true)
+ .build();
+
+ Security.insertProviderAt(conscryptProvider, 1);
+
final SSLContext sslContext = SSLContexts.custom()
- .setProvider(Conscrypt.newProvider())
.build();
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
.setH2Config(h2Config)
+ // For JRE versions 11 or newer the standard H2ClientTlsStrategy should be used instead
.setTlsStrategy(new ConscryptClientTlsStrategy(sslContext))
+ .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.setStreamListener(new H2StreamListener() {
@Override