Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2249

Regression in HTTP client/core

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.2
    • 5.2.1
    • HttpClient (async)
    • 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

          Activity

            People

              Unassigned Unassigned
              jenschude Jens Schulze
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: