From 41e64b2f8ac1c48664d887b811f878d5538d6d53 Mon Sep 17 00:00:00 2001 From: sixcorners Date: Mon, 10 Feb 2025 10:33:45 -0500 Subject: [PATCH] Remove the Origin header Fixes "Rejected an incoming WebSocket connection from the http://localhost:9222 origin. Use the command line flag --remote-allow-origins=http://localhost:9222 to allow connections from this origin or --remote-allow-origins=* to allow all origins." Fixes #98 --- .../cdt/services/impl/WebSocketServiceImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cdt-java-client/src/main/java/com/github/kklisura/cdt/services/impl/WebSocketServiceImpl.java b/cdt-java-client/src/main/java/com/github/kklisura/cdt/services/impl/WebSocketServiceImpl.java index 27c08f3d..366c34de 100644 --- a/cdt-java-client/src/main/java/com/github/kklisura/cdt/services/impl/WebSocketServiceImpl.java +++ b/cdt-java-client/src/main/java/com/github/kklisura/cdt/services/impl/WebSocketServiceImpl.java @@ -29,7 +29,10 @@ import com.github.kklisura.cdt.services.factory.impl.DefaultWebSocketContainerFactory; import java.io.IOException; import java.net.URI; +import java.util.List; +import java.util.Map; import java.util.function.Consumer; +import javax.websocket.ClientEndpointConfig; import javax.websocket.CloseReason; import javax.websocket.DeploymentException; import javax.websocket.Endpoint; @@ -114,6 +117,15 @@ public void onError(Session session, Throwable thr) { webSocketService.onError(session, thr); } }, + ClientEndpointConfig.Builder.create() + .configurator( + new ClientEndpointConfig.Configurator() { + @Override + public void beforeRequest(Map> headers) { + headers.remove("Origin"); + } + }) + .build(), uri); } catch (DeploymentException | IOException e) { LOGGER.warn("Failed connecting to ws server {}...", uri, e);