I'm using org.apache.hc.client5.http.impl.async.HttpAsyncClients.create() to create org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient for my HTTP/2 requests. I'm looking for some functionality to abort the request after reading some amount of data from the socket channel.
i tried with the cancel(mayInterruptIfRunning) method from the Future instance. But after abort it i can't get the response headers and the downloaded content.
Future<SimpleHttpResponse> future = null;
CloseableHttpAsyncClient httpClient = null;
try {
httpClient = httpAsyncClientBuilder.build();
httpClient.start();
future = httpClient.execute(target, asyncRequestProducer, SimpleResponseConsumer.create(), null, this.httpClientContext, this);
future.get(10, TimeUnit.SECONDS);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
httpClient.close(CloseMode.GRACEFUL);
}
Is there any other way to achieve this with httpclient-5.x?
Thanks in advance.