This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new d0fa3a6594 Optimise WebSocket client processing of server HTTP
responses
d0fa3a6594 is described below
commit d0fa3a659472a6eb49a94e8a54041c9853f29b10
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Jun 25 15:43:05 2026 +0100
Optimise WebSocket client processing of server HTTP responses
---
.../apache/tomcat/websocket/WsWebSocketContainer.java | 18 ++++++++----------
webapps/docs/changelog.xml | 4 ++++
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
index 881934dd39..8e750c38d7 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -848,6 +848,7 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
int status = 0;
boolean readStatus = false;
boolean readHeaders = false;
+ StringBuilder lineBuffer = new StringBuilder();
String line = null;
while (!readHeaders) {
// On entering loop buffer will be empty and at the start of a new
@@ -870,14 +871,13 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
}
response.flip();
while (response.hasRemaining() && !readHeaders) {
- if (line == null) {
- line = readLine(response);
- } else {
- line += readLine(response);
+ if (readLine(response, lineBuffer)) {
+ line = lineBuffer.toString();
+ lineBuffer = new StringBuilder();
}
if ("\r\n".equals(line)) {
readHeaders = true;
- } else if (line.endsWith("\r\n")) {
+ } else if (line != null && line.endsWith("\r\n")) {
if (readStatus) {
parseHeaders(line, headers);
} else {
@@ -927,20 +927,18 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
values.add(headerValue);
}
- private String readLine(ByteBuffer response) {
+ private boolean readLine(ByteBuffer response, StringBuilder sb) {
// All ISO-8859-1
- StringBuilder sb = new StringBuilder();
-
char c;
while (response.hasRemaining()) {
c = (char) response.get();
sb.append(c);
if (c == 10) {
- break;
+ return true;
}
}
- return sb.toString();
+ return false;
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 43d7f51daf..60b5d797c7 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -163,6 +163,10 @@
available buffer. Fix written by GPT-5.5. Test case written by Hironori
Ichimiya. (markt)
</fix>
+ <fix>
+ Optimise WebSocket client processing of server responses during
+ WebSocket HTTP upgrade process. (markt)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]