diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java index 68abf0aedc..427b5d27ed 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java @@ -47,11 +47,6 @@ public class BrotliInputStreamFactory implements InputStreamFactory { */ public static final String ENCODING = "br"; - @Override - public String getContentEncoding() { - return ENCODING; - } - /** * Default instance of {@link BrotliInputStreamFactory}. */ diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStreamFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStreamFactory.java index ab1a285ab2..ce56d8cb5d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStreamFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStreamFactory.java @@ -47,11 +47,6 @@ public class DeflateInputStreamFactory implements InputStreamFactory { */ public static final String ENCODING = "deflate"; - @Override - public String getContentEncoding() { - return ENCODING; - } - /** * Default instance of {@link DeflateInputStreamFactory}. */ diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/GZIPInputStreamFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/GZIPInputStreamFactory.java index f59712afe0..cda94373b7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/GZIPInputStreamFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/GZIPInputStreamFactory.java @@ -48,11 +48,6 @@ public class GZIPInputStreamFactory implements InputStreamFactory { */ public static final String ENCODING = "gzip"; - @Override - public String getContentEncoding() { - return ENCODING; - } - /** * Default instance of {@link GZIPInputStreamFactory}. */ diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java index b2664648e3..a6689435ef 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java @@ -38,21 +38,4 @@ public interface InputStreamFactory { InputStream create(InputStream inputStream) throws IOException; - /** - * Returns the canonical {@code Content-Encoding} token handled by this - * factory (for example {@code "gzip"}, {@code "deflate"}, {@code "br"}). - *

- * Implementations that do not represent a HTTP - * content-decoder should simply inherit the default implementation, - * which returns an empty string. - * - * @return the lower-case encoding token, or an empty string when the - * factory is not intended for HTTP content-decoding - * - * @since 5.6 - */ - default String getContentEncoding() { - return ""; - } - } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CommonsCompressDecoderFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CommonsCompressDecoderFactory.java index 412ba414b0..1dae2c8e6a 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CommonsCompressDecoderFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CommonsCompressDecoderFactory.java @@ -79,7 +79,6 @@ final class CommonsCompressDecoderFactory implements InputStreamFactory { this.encoding = encoding.toLowerCase(Locale.ROOT); } - @Override public String getContentEncoding() { return encoding; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentCoding.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentCoding.java index 3841a4ed01..3a8f169777 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentCoding.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/ContentCoding.java @@ -129,8 +129,6 @@ public String token() { * @return the matching enum constant, or {@code null} if none */ public static ContentCoding fromToken(final String token) { - return TOKEN_LOOKUP.get( - token == null ? null : token.toLowerCase(Locale.ROOT) - ); + return token != null ? TOKEN_LOOKUP.get(token.toLowerCase(Locale.ROOT)) : null; } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java index 4b9d7289d4..4a58972ae4 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java @@ -29,17 +29,14 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.zip.GZIPInputStream; import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.entity.DecompressingEntity; -import org.apache.hc.client5.http.entity.DeflateInputStream; import org.apache.hc.client5.http.entity.InputStreamFactory; import org.apache.hc.client5.http.entity.compress.ContentCoding; import org.apache.hc.client5.http.entity.compress.ContentDecoderRegistry; @@ -60,7 +57,6 @@ import org.apache.hc.core5.http.message.MessageSupport; import org.apache.hc.core5.http.message.ParserCursor; import org.apache.hc.core5.util.Args; -import org.brotli.dec.BrotliInputStream; /** * Request execution handler in the classic request execution chain @@ -81,68 +77,40 @@ public final class ContentCompressionExec implements ExecChainHandler { private final Lookup decoderRegistry; private final boolean ignoreUnknown; - private static final Map DECODERS = ContentDecoderRegistry.getRegistry(); - - /** - * Pre-built list of all supported tokens (plus X-GZIP alias) for - * the Accept-Encoding header, to avoid reconstructing it every time. - */ - private static final List DEFAULT_ACCEPT_ENCODINGS; - static { - final List tmp = new ArrayList<>(DECODERS.size() + 1); - for (final ContentCoding coding : DECODERS.keySet()) { - tmp.add(coding.token()); - } - // add x-gzip alias if gzip is present - if (DECODERS.containsKey(ContentCoding.GZIP)) { - tmp.add(ContentCoding.X_GZIP.token()); - } - DEFAULT_ACCEPT_ENCODINGS = Collections.unmodifiableList(tmp); - } - public ContentCompressionExec( final List acceptEncoding, final Lookup decoderRegistry, final boolean ignoreUnknown) { - - final List encodingsHeader = acceptEncoding != null ? acceptEncoding : DEFAULT_ACCEPT_ENCODINGS; - - this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, encodingsHeader); - - if (decoderRegistry != null) { - this.decoderRegistry = decoderRegistry; - } else { - final RegistryBuilder builder = RegistryBuilder.create(); - DECODERS.forEach((coding, factory) -> - builder.register(coding.token(), factory)); - // register the x-gzip alias again - if (DECODERS.containsKey(ContentCoding.GZIP)) { - builder.register(ContentCoding.X_GZIP.token(), DECODERS.get(ContentCoding.GZIP)); - } - this.decoderRegistry = builder.build(); - } - + this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, + Args.notEmpty(acceptEncoding, "Encoding list")); + this.decoderRegistry = Args.notNull(decoderRegistry, "Decoder register"); this.ignoreUnknown = ignoreUnknown; } public ContentCompressionExec(final boolean ignoreUnknown) { - this(null, null, ignoreUnknown); + final Map decoderMap = ContentDecoderRegistry.getRegistry(); + final RegistryBuilder builder = RegistryBuilder.create(); + final List acceptEncodingList = new ArrayList<>(decoderMap.size() + 1); + decoderMap.forEach((coding, factory) -> { + acceptEncodingList.add(coding.token()); + builder.register(coding.token(), factory); + }); + // register the x-gzip alias again + if (decoderMap.containsKey(ContentCoding.GZIP)) { + acceptEncodingList.add(ContentCoding.X_GZIP.token()); + builder.register(ContentCoding.X_GZIP.token(), decoderMap.get(ContentCoding.GZIP)); + } + this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, acceptEncodingList); + this.decoderRegistry = builder.build(); + this.ignoreUnknown = ignoreUnknown; } /** - * Handles {@code gzip} and {@code deflate} compressed entities by using the following - * decoders: - *

*/ public ContentCompressionExec() { - this(null, null, true); + this(true); } - @Override public ClassicHttpResponse execute( final ClassicHttpRequest request,