specify explicitly what encoders we support, don't rely on httpclient5 autodetection

This commit is contained in:
Athou
2025-12-23 16:02:52 +01:00
parent 2147aeb4ae
commit 863ced57f8
3 changed files with 16 additions and 11 deletions

View File

@@ -9,10 +9,13 @@ import java.time.Duration;
import java.time.Instant;
import java.time.InstantSource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;
import jakarta.inject.Singleton;
import jakarta.ws.rs.core.CacheControl;
@@ -24,6 +27,8 @@ import org.apache.hc.client5.http.SystemDefaultDnsResolver;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.config.TlsConfig;
import org.apache.hc.client5.http.entity.DeflateInputStream;
import org.apache.hc.client5.http.entity.InputStreamFactory;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
@@ -287,6 +292,10 @@ public class HttpGetter {
headers.add(new BasicHeader(HttpHeaders.PRAGMA, "No-cache"));
headers.add(new BasicHeader(HttpHeaders.CACHE_CONTROL, "no-cache"));
Map<String, InputStreamFactory> contentDecoderMap = new LinkedHashMap<>();
contentDecoderMap.put("gzip", GZIPInputStream::new);
contentDecoderMap.put("deflate", DeflateInputStream::new);
return HttpClientBuilder.create()
.useSystemProperties()
.disableAutomaticRetries()
@@ -296,6 +305,7 @@ public class HttpGetter {
.setConnectionManager(connectionManager)
.evictExpiredConnections()
.evictIdleConnections(TimeValue.of(idleConnectionsEvictionInterval))
.setContentDecoderRegistry(new LinkedHashMap<>(contentDecoderMap))
.build();
}

View File

@@ -3,7 +3,6 @@ quarkus.http.port=8082
quarkus.http.test-port=8085
quarkus.http.enable-compression=true
quarkus.http.enable-decompression=true
quarkus.http.compressors=gzip,deflate,br
# http cache
quarkus.http.static-resources.max-age=P365d

View File

@@ -11,7 +11,6 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPOutputStream;
@@ -35,7 +34,6 @@ import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
import org.mockserver.model.MediaType;
import com.aayushatharva.brotli4j.encoder.BrotliOutputStream;
import com.codahale.metrics.MetricRegistry;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.CommaFeedVersion;
@@ -309,10 +307,7 @@ class HttpGetterTest {
@Nested
class Compression {
@Test
void deflate() throws Exception {
supportsCompression("deflate", DeflaterOutputStream::new);
}
private static final String ACCEPT_ENCODING = "gzip, deflate";
@Test
void gzip() throws Exception {
@@ -320,8 +315,8 @@ class HttpGetterTest {
}
@Test
void br() throws Exception {
supportsCompression("br", BrotliOutputStream::new);
void deflate() throws Exception {
supportsCompression("deflate", DeflaterOutputStream::new);
}
void supportsCompression(String encoding, CompressionOutputStreamFunction compressionOutputStreamFunction) throws Exception {
@@ -329,8 +324,9 @@ class HttpGetterTest {
HttpGetterTest.this.mockServerClient.when(HttpRequest.request().withMethod("GET")).respond(req -> {
String acceptEncodingHeader = req.getFirstHeader(HttpHeaders.ACCEPT_ENCODING);
if (!Set.of(acceptEncodingHeader.split(", ")).contains(encoding)) {
throw new Exception(encoding + " should be in the Accept-Encoding header");
if (!ACCEPT_ENCODING.equals(acceptEncodingHeader)) {
throw new Exception("Wrong value in the Accept-Encoding header, should be '%s' but was '%s'".formatted(ACCEPT_ENCODING,
acceptEncodingHeader));
}
ByteArrayOutputStream output = new ByteArrayOutputStream();