Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

Adds test coverage for WebSocket upgrade behavior per JDK-8361305, which reports that direct WebSocket connections work but upgrades fail when HTTP/2 connections already exist to the same host.

Changes

  • NettyWebSocketServer - Netty-based WebSocket server supporting both HTTP/1.1 and WebSocket protocols on the same port for test scenarios
  • JavaHttpClientWebSocketTest - Two test cases:
    • testDirectWebSocketConnection() - Verifies ws:// URIs work with HttpClient.newWebSocketBuilder()
    • testWebSocketUpgradeAfterHttp2() - Tests WebSocket connection after HTTP request to same host:port

Test Behavior

// Test 1: Direct connection (works)
HttpClient client = HttpClient.newHttpClient();
WebSocket ws = client.newWebSocketBuilder()
    .buildAsync(URI.create("ws://localhost:8090/websocket"), listener)
    .get();

// Test 2: After HTTP connection to same host (documents JDK-8361305 scenario)
HttpClient client = HttpClient.newBuilder()
    .version(HttpClient.Version.HTTP_2)
    .build();
client.send(httpRequest, BodyHandlers.ofString());  // Establish HTTP connection
WebSocket ws = client.newWebSocketBuilder()
    .buildAsync(URI.create("ws://localhost:9090/websocket"), listener)
    .get();  // May fail per JDK-8361305

On Java 17.0.17, both scenarios pass, suggesting the issue may be resolved in this version. Tests provide baseline for verification across Java versions.

Original prompt

Add a new test case for WebSocketUpgradeSupport

There is an issue reported here https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8361305

We should include this as a new testcase as it is releated to the HttpClient as well so we need to proof:

Directly connecting to a Websocketserver works when using

HttpClient client = HttpClient.newHttpClient();
WebSocket.Builder webSocketBuilder = client.newWebSocketBuilder();

on a ws:// URI, but it doe NOT work to UPGRADE


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new test case for WebSocketUpgradeSupport Add WebSocket upgrade test cases for JDK-8361305 Nov 13, 2025
Copilot AI requested a review from laeubi November 13, 2025 16:04
Copilot finished work on behalf of laeubi November 13, 2025 16:04
@laeubi laeubi marked this pull request as ready for review November 13, 2025 16:19
@laeubi laeubi merged commit cad2a19 into main Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants