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


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java:
##########
@@ -201,6 +209,61 @@ public static List<String> variantNames(final 
MessageHeaders message) {
         return names;
     }
 
+    @Internal
+    public static void normalizeElements(final MessageHeaders message, final 
String headerName, final Consumer<String> consumer) {
+        // User-Agent as a special case due to its grammar
+        if (headerName.equalsIgnoreCase(HttpHeaders.USER_AGENT)) {
+            final Header header = message.getFirstHeader(headerName);
+            if (header != null) {
+                consumer.accept(header.getValue().toLowerCase(Locale.ROOT));
+            }
+        } else {
+            normalizeElements(message.headerIterator(headerName), consumer);
+        }
+    }
+
+    @Internal
+    public static void normalizeElements(final Iterator<Header> iterator, 
final Consumer<String> consumer) {
+        final List<HeaderElement> elements = new ArrayList<>();
+        final Iterator<HeaderElement> it = new 
BasicHeaderElementIterator(iterator);

Review Comment:
   We can streamline the process by using `StreamSupport.stream` to create a 
stream directly from the `Iterator<HeaderElement>`. This approach eliminates 
the need for an intermediate collection and allows us to process elements in a 
single pipeline, which is more memory-efficient and idiomatic to the stream API.



-- 
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