From 25d7b99ba1c00c75ad10140c0e9ee9c44e257de2 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 9 Jul 2020 08:11:05 +1000 Subject: [PATCH] Issue #5018 - add WebSocketClient UpgradeRequest timeout to jetty 10 Signed-off-by: Lachlan Roberts --- .../websocket/client/WebSocketClient.java | 2 -- .../impl/JettyClientUpgradeRequest.java | 30 +++++-------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index e6e59ba41c9b..ed36d8a09062 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -29,7 +29,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.eclipse.jetty.client.HttpClient; @@ -132,7 +131,6 @@ public CompletableFuture connect(Object websocket, URI toUri, ClientUpg } JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(coreClient, request, toUri, frameHandlerFactory, websocket); - upgradeRequest.timeout(request.getTimeout(), TimeUnit.MILLISECONDS); upgradeRequest.setConfiguration(configurationCustomizer); if (upgradeListener != null) { diff --git a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java index 0f6ddeeef99e..b3f0abd85079 100644 --- a/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java +++ b/jetty-websocket/websocket-jetty-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java @@ -18,30 +18,27 @@ package org.eclipse.jetty.websocket.client.impl; -import java.net.HttpCookie; import java.net.URI; -import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.eclipse.jetty.client.HttpResponse; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; -import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.websocket.api.UpgradeRequest; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler; import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; -public class JettyClientUpgradeRequest extends ClientUpgradeRequest +public class JettyClientUpgradeRequest extends org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest { private final DelegatedJettyClientUpgradeRequest handshakeRequest; private final JettyWebSocketFrameHandler frameHandler; - public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, UpgradeRequest request, URI requestURI, JettyWebSocketFrameHandlerFactory frameHandlerFactory, + public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, ClientUpgradeRequest request, URI requestURI, JettyWebSocketFrameHandlerFactory frameHandlerFactory, Object websocketPojo) { super(coreClient, requestURI); @@ -53,15 +50,7 @@ public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, UpgradeRequest request.getHeaders().forEach(fields::put); // Copy manually created Cookies into place - List cookies = request.getCookies(); - if (cookies != null) - { - // TODO: remove existing Cookie header (if set)? - for (HttpCookie cookie : cookies) - { - fields.add(HttpHeader.COOKIE, cookie.toString()); - } - } + request.getCookies().forEach(c -> fields.add(HttpHeader.COOKIE, c.toString())); // Copy sub-protocols setSubProtocols(request.getSubProtocols()); @@ -71,13 +60,8 @@ public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, UpgradeRequest .map(c -> new ExtensionConfig(c.getName(), c.getParameters())) .collect(Collectors.toList())); - // Copy method from upgradeRequest object - if (request.getMethod() != null) - method(request.getMethod()); - - // Copy version from upgradeRequest object - if (request.getHttpVersion() != null) - version(HttpVersion.fromString(request.getHttpVersion())); + // Copy timeout from upgradeRequest object + timeout(request.getTimeout(), TimeUnit.MILLISECONDS); } handshakeRequest = new DelegatedJettyClientUpgradeRequest(this);