From 7e9700fb9a897db4d4a1bcbbbbcaf1e390c9b2f5 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 19 Mar 2019 14:38:17 +1100 Subject: [PATCH] Issue #3462 - changes from review Signed-off-by: Lachlan Roberts --- .../core/client/ClientUpgradeRequest.java | 21 ++++++------------- .../websocket/core/server/Negotiation.java | 19 +++++++++-------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java index 8296e3ec6fa..4f6d9f556f5 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java @@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.ThreadLocalRandom; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpConversation; @@ -44,7 +45,6 @@ import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpVersion; -import org.eclipse.jetty.http.QuotedCSV; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; @@ -139,14 +139,10 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon public List getExtensions() { - List extensions = new ArrayList<>(); - - getHeaders().stream() - .filter(field -> field.getName().equalsIgnoreCase(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.toString())) - .forEach(field -> new QuotedCSV(field.getValue()).getValues().stream() - .map(ExtensionConfig::parse) - .forEach(extensions::add) - ); + List extensions = getHeaders().getCSV(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, true) + .stream() + .map(ExtensionConfig::parse) + .collect(Collectors.toList()); return extensions; } @@ -161,12 +157,7 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon public List getSubProtocols() { - List subProtocols = new ArrayList<>(); - - getHeaders().stream() - .filter(field -> field.getName().equalsIgnoreCase(HttpHeader.SEC_WEBSOCKET_SUBPROTOCOL.toString())) - .forEach(field -> subProtocols.addAll(new QuotedCSV(field.getValue()).getValues())); - + List subProtocols = getHeaders().getCSV(HttpHeader.SEC_WEBSOCKET_SUBPROTOCOL, true); return subProtocols; } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java index 22389e485d9..6c21e1cf777 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java @@ -18,6 +18,16 @@ package org.eclipse.jetty.websocket.core.server; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.QuotedCSV; @@ -28,15 +38,6 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; -import java.util.stream.Collectors; - public class Negotiation { private final Request baseRequest;