Skip to content

Commit

Permalink
[java] Handling case where -1 is returned as statusCode
Browse files Browse the repository at this point in the history
Closes #11910
  • Loading branch information
diemol committed Apr 25, 2023
1 parent 98d3e26 commit 1ea3134
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,17 @@ public WebSocket send(Message message) {
LOG.fine("Sending text message: " + textMessage.text());
makeCall = () -> underlyingSocket.sendText(textMessage.text(), true);
} else if (message instanceof CloseMessage) {
LOG.fine("Sending close message");
CloseMessage closeMessage = (CloseMessage) message;
makeCall = () -> underlyingSocket.sendClose(closeMessage.code(), closeMessage.reason());
if (!underlyingSocket.isOutputClosed()) {
// Sometimes the statusCode is -1, which could mean the socket is already closed.
// We send a normal closure code in that case, though
int statusCode = closeMessage.code() == -1 ? 1000 : closeMessage.code();
LOG.fine(() -> String.format("Sending close message, statusCode %s, reason: %s", statusCode, closeMessage.reason()));
makeCall = () -> underlyingSocket.sendClose(statusCode, closeMessage.reason());
} else {
LOG.fine("Output is closed, not sending close message");
return this;
}
} else {
throw new IllegalArgumentException("Unsupported message type: " + message);
}
Expand Down

0 comments on commit 1ea3134

Please sign in to comment.