Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
5.3.1
-
None
Description
Make an HTTP request that is retried (e.g. response status 429). The HTTP headers of the retried request does not include an `Accept-Encoding` header.
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.impl.io.DefaultClassicHttpRequestFactory; import org.junit.jupiter.api.Test; import org.mockserver.integration.ClientAndServer; import org.mockserver.model.HttpRequest; import org.mockserver.socket.PortFactory; import java.io.IOException; import java.io.UncheckedIOException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; public class ApacheTest { @Test void repeatedRequestHasNoAcceptEncodingHeader() { int serverPort = PortFactory.findFreePort(); String serverUrl = "http://localhost:" + serverPort; ClientAndServer server = ClientAndServer.startClientAndServer(serverPort); server.when(request()).respond(response().withStatusCode(429)); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { ClassicHttpRequest request = DefaultClassicHttpRequestFactory.INSTANCE.newHttpRequest("GET", serverUrl); httpClient.execute(request, HttpClientContext.create(), r -> r); } catch (IOException e) { throw new UncheckedIOException(e.getMessage(), e); } HttpRequest[] sentRequests = server.retrieveRecordedRequests(null); assertThat(sentRequests).satisfiesExactly( first -> assertThat(first.getHeaderList()).extracting(h -> h.getName().getValue()) .containsExactlyInAnyOrder("content-length", "Connection", "User-Agent", "Host", "Accept-Encoding"), second -> assertThat(second.getHeaderList()).extracting(h -> h.getName().getValue()) .containsExactlyInAnyOrder("content-length", "Connection", "User-Agent", "Host") ); } }