Hi,

version 5.2 includes this commit https://github.com/apache/httpcomponents-core/commit/6741e3c555b96c4a64358adcb69aa0fddeb735b1

This 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 com.commercetools.http.apachehttp;

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;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.junit.jupiter.api.Test;

import java.util.concurrent.*;

public class SupplierTest {

    @Test
    public void reproduceHostError() {
        final Executor executor = new ForkJoinPool();
        final CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create().setVersionPolicy(HttpVersionPolicy.NEGOTIATE).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 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.

Greetings

Jens

--

*Jens Schulze*
Software Engineer

E. jens.schu...@commercetools.com
T. +49 (30) 467 24 21-20
commercetools GmbH | Ritterstr. 7 | 10969 Berlin


--

*commercetools GmbH*
Adams-Lehmann-Straße 44 | 80797 Munich | Germany
Register: HRB 161496 | Local Court at Munich
Managing Directors: Dirk Hörig | Denis Werner

Information on data protection and your rights as data subjects can be found here <https://commercetools.com/privacy>.



--
commercetools
Germany, Munich - Berlin - Jena - Cologne | The Netherlands, Amsterdam | United Kingdom, London   Spain, Valencia | Switzerland, Zürich | United States, Durham | Singapore, Singapore | Australia, Sydney




<https://commercetools.com/resources/report-access-center>

Reply via email to