[
https://issues.apache.org/jira/browse/HTTPASYNC-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17807148#comment-17807148
]
Oleg Kalnichevski commented on HTTPASYNC-171:
---------------------------------------------
[~tassadar] Of course, there is.
{code:java}
final PoolingAsyncClientConnectionManager cm =
PoolingAsyncClientConnectionManagerBuilder.create()
.setTlsConfigResolver(httphost -> TlsConfig.custom()
// .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1)
// .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
.setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.build())
.build();
try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
.setConnectionManager(cm)
.build()) {
client.start();
final HttpHost target = new HttpHost("https", "httpbin.org");
final HttpClientContext clientContext = HttpClientContext.create();
final SimpleHttpRequest request = SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
.build();
System.out.println("Executing request " + request);
final Future<SimpleHttpResponse> future = client.execute(
SimpleRequestProducer.create(request),
SimpleResponseConsumer.create(),
clientContext,
new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(final SimpleHttpResponse response) {
System.out.println(request + "->" + new StatusLine(response));
System.out.println("HTTP protocol " +
clientContext.getProtocolVersion());
final SSLSession sslSession = clientContext.getSSLSession();
if (sslSession != null) {
System.out.println("SSL protocol " +
sslSession.getProtocol());
System.out.println("SSL cipher suite " +
sslSession.getCipherSuite());
}
System.out.println(response.getBody());
}
@Override
public void failed(final Exception ex) {
System.out.println(request + "->" + ex);
}
@Override
public void cancelled() {
System.out.println(request + " cancelled");
}
});
future.get();
System.out.println("Shutting down");
client.close(CloseMode.GRACEFUL);
{code}
Oleg
> Async http post with apache client 5.3
> --------------------------------------
>
> Key: HTTPASYNC-171
> URL: https://issues.apache.org/jira/browse/HTTPASYNC-171
> Project: HttpComponents HttpAsyncClient
> Issue Type: Bug
> Reporter: tassadar
> Priority: Major
>
> I constructed an async client with:
> {code:java}
> private val httpclient = HttpAsyncClients.custom()
> .setConnectionManager(connectionManager)
> .build();{code}
> {color:#172b4d}And i noticed that the Content-Length header is not supplied.
> Invastigating i saw that all the requesta were made as http 2.0, so i tried
> to force an http 1.1 request:
> {color}
> {code:java}
> request.setVersion(HttpVersion.HTTP_1_1)
> localContext.setProtocolVersion(HttpVersion.HTTP_1_1){code}
> but it didn't worked, still the request were made as http 2.0. Trying to
> investigate further i noticed that even if the{color:#172b4d}
> H2RequestContent interceptor is able to manage the http 1.1 request
> (delegating it to super) the
> {color}AbstractH2StreamMultiplexer.{color:#172b4d}getProtocolVersion()
> involved in the process always returns {color}http_2:
> {code:java}
> @Override
> public ProtocolVersion getProtocolVersion() {
> return HttpVersion.HTTP_2;
> }{code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]