ffang commented on code in PR #3620:
URL: https://github.com/apache/cxf/pull/3620#discussion_r4389980701


##########
rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java:
##########
@@ -516,30 +521,90 @@ && isResponseBodyAvailable()) {
         boolean addHeaders = MessageUtils.getContextualBoolean(message, 
ADD_HEADERS_PROPERTY, false);
         for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
             String header = entry.getKey();
-            List<?> headerList = entry.getValue();
-
+            List<String> values = responseHeaderValues(header, 
entry.getValue(), addHeaders);
             if (addHeaders || isSingleHeader(header)) {
-                for (int i = 0; i < headerList.size(); i++) {
-                    Object headerObject = headerList.get(i);
-                    if (headerObject != null) {
-                        response.addHeader(header, 
headerObjectToString(headerObject));
-                    }
+                for (String value : values) {
+                    response.addHeader(header, value);
                 }
             } else {
-                StringBuilder sb = new StringBuilder();
-                for (int i = 0; i < headerList.size(); i++) {
-                    Object headerObject = headerList.get(i);
-                    if (headerObject != null) {
-                        sb.append(headerObjectToString(headerObject));
-                    }
-
-                    if (i + 1 < headerList.size()) {
-                        sb.append(',');
-                    }
+                response.setHeader(header, values.get(0));
+            }
+        }
+    }
+
+    static Map<String, List<String>> getResponseHeaders(Message message, 
HttpServletResponse response) {
+        Map<String, List<String>> protocol = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        Map<String, List<String>> original = CastUtils.cast((Map<?, 
?>)message.get(Message.PROTOCOL_HEADERS));
+        if (original != null) {
+            protocol.putAll(original);
+        }
+        return new Headers(message, protocol).getResponseHeaders(response);
+    }
+
+    /** Returns a snapshot without modifying the servlet response or the 
protocol headers. */
+    private Map<String, List<String>> getResponseHeaders(HttpServletResponse 
response) {

Review Comment:
   Done. `getResponseHeaders(Message, HttpServletResponse)` is now a single 
static method, and the helpers it uses (`getContentTypeFromMessage`, 
`isResponseBodyAvailable`, `isSingleHeader`, `headerObjectToString`) are static 
and take the message or headers as arguments. `copyToResponse` uses them the 
same way as before.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to