This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new d49dff2286 Optimise WebSocket client processing of server HTTP
responses
d49dff2286 is described below
commit d49dff2286a5d870b073044615b8df8abe7f683b
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 871c251ed3..1ca088bc55 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -855,6 +855,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
@@ -877,14 +878,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 {
@@ -934,20 +934,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 46ff203a06..7264e323fa 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]