arturobernalg commented on code in PR #651:
URL: 
https://github.com/apache/httpcomponents-client/pull/651#discussion_r2156731216


##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java:
##########
@@ -81,36 +81,47 @@ public final class ContentCompressionExec implements 
ExecChainHandler {
     private final Lookup<InputStreamFactory> decoderRegistry;
     private final boolean ignoreUnknown;
 
+    private static final Map<ContentCoding, InputStreamFactory> 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<String> DEFAULT_ACCEPT_ENCODINGS;
+    static {
+        final List<String> 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<String> acceptEncoding,
             final Lookup<InputStreamFactory> decoderRegistry,
             final boolean ignoreUnknown) {
 
-        final boolean brotliSupported = decoderRegistry == null && 
BrotliDecompressingEntity.isAvailable();
-        if (acceptEncoding != null) {
-            this.acceptEncoding = 
MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, acceptEncoding);
-        } else {
-            final List<String> encodings = new ArrayList<>(4);
-            encodings.add("gzip");
-            encodings.add("x-gzip");
-            encodings.add("deflate");
-            if (brotliSupported) {
-                encodings.add("br");
-            }
-            this.acceptEncoding = 
MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, encodings);
-        }
+        final List<String> encodingsHeader = acceptEncoding != null ? 
acceptEncoding : DEFAULT_ACCEPT_ENCODINGS;

Review Comment:
   @ok2c Do you want me to do some change? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to