Skip to content

Commit

Permalink
Issue #5018 - add WebSocketClient UpgradeRequest timeout to jetty 10
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Jul 8, 2020
1 parent a179535 commit 25d7b99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +131,6 @@ public CompletableFuture<Session> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,15 +50,7 @@ public JettyClientUpgradeRequest(WebSocketCoreClient coreClient, UpgradeRequest
request.getHeaders().forEach(fields::put);

// Copy manually created Cookies into place
List<HttpCookie> 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());
Expand All @@ -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);
Expand Down

0 comments on commit 25d7b99

Please sign in to comment.