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

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new e4f6a6d4c8 Add check to prevent redundant values in headers when using 
GZIPOutInterceptor (#1819)
e4f6a6d4c8 is described below

commit e4f6a6d4c8ce365c4b0a96041de702297d3e3f18
Author: Yoann Vernageau <6807151+yv...@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
---
 .../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) {

Reply via email to