You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2024/05/01 00:14:35 UTC

(cxf) 01/12: Add check to prevent redundant values in headers when using GZIPOutInterceptor (#1819)

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

reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit ecc1fb7d95b7ac87237bcaaff223b9f6a0aae2ab
Author: Yoann Vernageau <68...@users.noreply.github.com>
AuthorDate: Sat Apr 20 17:57:16 2024 +0200

    Add check to prevent redundant values in headers when using GZIPOutInterceptor (#1819)
    
    * Add check to prevent redundant values in headers when using GZIPOutInterceptor
    
    * Simplify GZIPOutInterceptor#addHeader
    
    (cherry picked from commit e4f6a6d4c8ce365c4b0a96041de702297d3e3f18)
---
 .../cxf/transport/common/gzip/GZIPOutInterceptor.java | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java b/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
index 8a80d07a17..d7fc1686d8 100644
--- a/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
@@ -323,21 +323,14 @@ public class GZIPOutInterceptor extends AbstractPhaseInterceptor<Message> {
      * @param value the value to add
      */
     private static void addHeader(Message message, String name, String value) {
-        Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>)message
-            .get(Message.PROTOCOL_HEADERS));
-        if (protocolHeaders == null) {
-            protocolHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-            message.put(Message.PROTOCOL_HEADERS, protocolHeaders);
+        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        if (headers == null) {
+            headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+            message.put(Message.PROTOCOL_HEADERS, headers);
         }
-        List<String> header = CastUtils.cast((List<?>)protocolHeaders.get(name));
-        if (header == null) {
-            header = new ArrayList<>();
-            protocolHeaders.put(name, header);
-        }
-        if (header.isEmpty()) {
+        List<String> header = headers.computeIfAbsent(name, k -> new ArrayList<>());
+        if (header.isEmpty() || !header.contains(value)) {
             header.add(value);
-        } else {
-            header.set(0, header.get(0) + "," + value);
         }
     }
     public void setForce(boolean force) {