diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java index d3c8b05edd..92475b9cad 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java @@ -28,6 +28,7 @@ package org.apache.hc.client5.http.impl.classic; import java.io.Closeable; +import java.io.InputStream; import java.net.ProxySelector; import java.security.AccessController; import java.security.PrivilegedAction; @@ -58,6 +59,8 @@ import org.apache.hc.client5.http.entity.InputStreamFactory; import org.apache.hc.client5.http.entity.compress.ContentCodecRegistry; import org.apache.hc.client5.http.entity.compress.ContentCoding; +import org.apache.hc.client5.http.entity.compress.DecompressingEntity; +import org.apache.hc.client5.http.entity.compress.IOFunction; import org.apache.hc.client5.http.impl.ChainElement; import org.apache.hc.client5.http.impl.CookieSpecSupport; import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy; @@ -215,8 +218,6 @@ private ExecInterceptorEntry( private BackoffManager backoffManager; private Lookup authSchemeRegistry; private Lookup cookieSpecRegistry; - @Deprecated - private LinkedHashMap contentDecoderMap; private CookieStore cookieStore; private CredentialsProvider credentialsProvider; private String userAgent; @@ -243,7 +244,7 @@ private ExecInterceptorEntry( * Custom decoders keyed by {@link ContentCoding}. * */ - private LinkedHashMap> contentDecoder; + private LinkedHashMap> contentDecoder; public static HttpClientBuilder create() { return new HttpClientBuilder(); @@ -706,11 +707,21 @@ public final HttpClientBuilder setDefaultCookieSpecRegistry( * Sets a map of {@link org.apache.hc.client5.http.entity.InputStreamFactory}s * to be used for automatic content decompression. * + * @deprecated Populate via {@link #setContentDecoder(LinkedHashMap)} + * * @return this instance. */ + @Deprecated public final HttpClientBuilder setContentDecoderRegistry( final LinkedHashMap contentDecoderMap) { - this.contentDecoderMap = contentDecoderMap; + if (contentDecoderMap != null) { + final LinkedHashMap> map = new LinkedHashMap<>(); + for (final Map.Entry e : contentDecoderMap.entrySet()) { + final IOFunction decoderFunc = e.getValue()::create; + map.put(e.getKey(), srcEntity -> new DecompressingEntity(srcEntity, decoderFunc)); + } + this.contentDecoder = map; + } return this; } @@ -725,7 +736,7 @@ public final HttpClientBuilder setContentDecoderRegistry( * @since 5.6 */ public final HttpClientBuilder setContentDecoder( - final LinkedHashMap> contentDecoder) { + final LinkedHashMap> contentDecoder) { this.contentDecoder = contentDecoder; return this; } @@ -995,8 +1006,8 @@ public CloseableHttpClient build() { if (contentDecoder != null) { final List encodings = new ArrayList<>(contentDecoder.size()); final RegistryBuilder> b2 = RegistryBuilder.create(); - for (final Map.Entry> entry : contentDecoder.entrySet()) { - final String token = entry.getKey().token(); + for (final Map.Entry> entry : contentDecoder.entrySet()) { + final String token = entry.getKey(); encodings.add(token); b2.register(token, entry.getValue()); }