You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/08/05 17:36:31 UTC

(httpcomponents-client) branch master updated: Unsupported content encoding to be treated as an error

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 97e4041ad Unsupported content encoding to be treated as an error
97e4041ad is described below

commit 97e4041ad63bf2ccdc809d8ed0b30002b6d6a250
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Aug 5 10:50:17 2025 +0200

    Unsupported content encoding to be treated as an error
---
 .../http/impl/async/ContentCompressionAsyncExec.java     |  5 +----
 .../http/impl/classic/ContentCompressionExec.java        | 16 +++-------------
 .../hc/client5/http/impl/classic/HttpClientBuilder.java  |  4 ++--
 .../http/impl/classic/TestContentCompressionExec.java    |  2 +-
 4 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
index 519f808b4..d5a105c7c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
@@ -62,7 +62,6 @@
 public final class ContentCompressionAsyncExec implements AsyncExecChainHandler {
 
     private final Lookup<UnaryOperator<AsyncDataConsumer>> decoders;
-    private final boolean ignoreUnknown;
 
     public ContentCompressionAsyncExec(
             final LinkedHashMap<String, UnaryOperator<AsyncDataConsumer>> decoderMap,
@@ -73,7 +72,6 @@ public ContentCompressionAsyncExec(
         final RegistryBuilder<UnaryOperator<AsyncDataConsumer>> rb = RegistryBuilder.create();
         decoderMap.forEach(rb::register);
         this.decoders = rb.build();
-        this.ignoreUnknown = ignoreUnknown;
     }
 
     /**
@@ -86,7 +84,6 @@ public ContentCompressionAsyncExec() {
         this.decoders = RegistryBuilder.<UnaryOperator<AsyncDataConsumer>>create()
                 .register(ContentCoding.DEFLATE.token(), map.get(ContentCoding.DEFLATE.token()))
                 .build();
-        this.ignoreUnknown = true;
     }
 
 
@@ -132,7 +129,7 @@ public AsyncDataConsumer handleResponse(final HttpResponse rsp,
                         final UnaryOperator<AsyncDataConsumer> op = decoders.lookup(token);
                         if (op != null) {
                             downstream = op.apply(downstream);
-                        } else if (!ignoreUnknown) {
+                        } else {
                             throw new HttpException("Unsupported Content-Encoding: " + token);
                         }
                     }
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 06d5b114e..c6491ec3e 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
@@ -75,19 +75,16 @@ public final class ContentCompressionExec implements ExecChainHandler {
 
     private final Header acceptEncoding;
     private final Lookup<UnaryOperator<HttpEntity>> decoderRegistry;
-    private final boolean ignoreUnknown;
 
     public ContentCompressionExec(
             final List<String> acceptEncoding,
-            final Lookup<UnaryOperator<HttpEntity>> decoderRegistry,
-            final boolean ignoreUnknown) {
+            final Lookup<UnaryOperator<HttpEntity>> decoderRegistry) {
         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) {
+    public ContentCompressionExec() {
         final Map<ContentCoding, UnaryOperator<HttpEntity>> decoderMap = new EnumMap<>(ContentCoding.class);
         for (final ContentCoding c : ContentCoding.values()) {
             final UnaryOperator<HttpEntity> d = ContentCodecRegistry.decoder(c);
@@ -109,13 +106,6 @@ public ContentCompressionExec(final boolean ignoreUnknown) {
         }
         this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, acceptList);
         this.decoderRegistry = builder.build();
-        this.ignoreUnknown = ignoreUnknown;
-    }
-
-    /**
-     */
-    public ContentCompressionExec() {
-        this(true);
     }
 
     @Override
@@ -152,7 +142,7 @@ public ClassicHttpResponse execute(
                         response.removeHeaders(HttpHeaders.CONTENT_LENGTH);
                         response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
                         response.removeHeaders(HttpHeaders.CONTENT_MD5);
-                    } else if (!"identity".equals(codecname) && !ignoreUnknown) {
+                    } else if (!"identity".equals(codecname)) {
                         throw new HttpException("Unsupported Content-Encoding: " + codec.getName());
                     }
                 }
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 a9483d613..9d17ff78d 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
@@ -981,13 +981,13 @@ public CloseableHttpClient build() {
                 final Registry<UnaryOperator<HttpEntity>> decoderRegistry = b2.build();
 
                 execChainDefinition.addFirst(
-                        new ContentCompressionExec(encodings, decoderRegistry, true),
+                        new ContentCompressionExec(encodings, decoderRegistry),
                         ChainElement.COMPRESS.name());
 
             } else {
                 // Use the default decoders from ContentCodecRegistry
                 execChainDefinition.addFirst(
-                        new ContentCompressionExec(true),
+                        new ContentCompressionExec(),
                         ChainElement.COMPRESS.name());
             }
         }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
index e6084952c..d9c5151d6 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java
@@ -206,7 +206,7 @@ void testUnknownContentEncoding() throws Exception {
         final HttpEntity original = EntityBuilder.create().setText("encoded stuff").setContentEncoding("whatever").build();
         response.setEntity(original);
 
-        impl = new ContentCompressionExec(false);
+        impl = new ContentCompressionExec();
 
         Mockito.when(execChain.proceed(request, scope)).thenReturn(response);