Skip to content

Commit 4d4bb30

Browse files
committed
Added Cookie to websocket connection
1 parent a744046 commit 4d4bb30

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/main/java/org/javawebstack/httpclient/HTTPClient.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ public WebSocket webSocket(String path, WebSocketHandler handler, Map<String, St
183183
HTTPClientSocket socket = new HTTPClientSocket(getBaseUrl() + ((path.startsWith("/") || path.startsWith("http://") || path.startsWith("https://") || path.startsWith("ws://") || path.startsWith("wss://")) ? "" : "/") + path, !isSSLVerification());
184184
if(additionalHeaders != null)
185185
additionalHeaders.forEach(socket::setRequestHeader);
186+
187+
List<String> reqCookies = new ArrayList<>();
188+
for(HttpCookie cookie : defaultCookies)
189+
reqCookies.add(cookie.getName()+"="+cookie.getValue());
190+
if (reqCookies.size() > 0)
191+
socket.setRequestHeader("Cookie", String.join("; ", reqCookies));
192+
186193
WebSocket webSocket = new WebSocket(socket, handler);
187194
new Thread(webSocket).start();
188195
return webSocket;

0 commit comments

Comments
 (0)