Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
5.2
-
None
Description
This commit https://github.com/apache/httpcomponents-core/commit/6741e3c555b96c4a64358adcb69aa0fddeb735b1 introduced a regression in either Core or Client.
It leads to failing requests with "ProtocolException: Header `Host` is illegal" also the initiating request didn't included the mentioned header. I created a small reproducer:
package test.http.apachehttp; import java.util.concurrent.*; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; import org.apache.hc.client5.http.async.methods.SimpleResponseConsumer; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.nio.AsyncRequestProducer; import org.apache.hc.core5.http.nio.support.AsyncRequestBuilder; public class HttpTest { // @Test public void reproduceHostError() { final Executor executor = new ForkJoinPool(); final CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create().build(); client.start(); AsyncRequestProducer p = AsyncRequestBuilder.get("https://google.com").build(); final SimpleHttpResponse response1 = execute(executor, client, p).join(); final SimpleHttpResponse response2 = execute(executor, client, p).join(); final SimpleHttpResponse response3 = execute(executor, client, p).join(); // final SimpleHttpResponse response4 = execute(executor, client, p).join(); final int code = response1.getCode(); } private CompletableFuture<SimpleHttpResponse> execute(Executor executor, CloseableHttpAsyncClient client, AsyncRequestProducer p) { final CompletableFuture<SimpleHttpResponse> apacheResponseFuture = new CompletableFuture<>(); client.execute(p, SimpleResponseConsumer.create(), new FutureCallback<SimpleHttpResponse>() { @Override public void completed(SimpleHttpResponse result) { apacheResponseFuture.complete(result); } @Override public void failed(Exception ex) { apacheResponseFuture.completeExceptionally(ex); } @Override public void cancelled() { apacheResponseFuture.cancel(true); } }); return apacheResponseFuture.thenApplyAsync(simpleHttpResponse1 -> simpleHttpResponse1, executor); } }
The 3rd request will fail with the mentioned ProtocolException.
Attachments
Issue Links
- is duplicated by
-
HTTPCLIENT-2251 [5.2] Consistent ProtocolException the second time a request is executed
- Closed