This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 8f20e71868 Minor optimisation - remove unnecessary code
8f20e71868 is described below

commit 8f20e7186830f25072d879274bcba5774a765ff5
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Mar 11 09:31:29 2026 +0000

    Minor optimisation - remove unnecessary code
    
    Obsolete header unfolding (RFC9112 allows the receiving server to
    replace it with a single space) is performed in HttpHeaderParser so
    whitespace when parsing individual headers is limited to space or tab.
---
 .../apache/tomcat/util/http/parser/EntityTag.java  |  4 +--
 .../apache/tomcat/util/http/parser/HttpParser.java | 33 +++++++++++-----------
 .../apache/tomcat/util/http/parser/Upgrade.java    |  6 ++--
 .../tomcat/util/http/parser/TestMediaType.java     |  6 ++--
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/parser/EntityTag.java 
b/java/org/apache/tomcat/util/http/parser/EntityTag.java
index 298e251b24..c2979f32e5 100644
--- a/java/org/apache/tomcat/util/http/parser/EntityTag.java
+++ b/java/org/apache/tomcat/util/http/parser/EntityTag.java
@@ -51,7 +51,7 @@ public class EntityTag {
 
         while (true) {
             boolean strong = false;
-            HttpParser.skipLws(input);
+            HttpParser.skipWhitespace(input);
 
             switch (HttpParser.skipConstant(input, "W/")) {
                 case EOF:
@@ -79,7 +79,7 @@ public class EntityTag {
                 }
             }
 
-            HttpParser.skipLws(input);
+            HttpParser.skipWhitespace(input);
 
             switch (HttpParser.skipConstant(input, ",")) {
                 case EOF:
diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java 
b/java/org/apache/tomcat/util/http/parser/HttpParser.java
index 196d4df4eb..2b8e2bcc48 100644
--- a/java/org/apache/tomcat/util/http/parser/HttpParser.java
+++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java
@@ -399,15 +399,16 @@ public class HttpParser {
     }
 
 
-    // Skip any LWS and position to read the next character. The next character
-    // is returned as being able to 'peek()' it allows a small optimisation in
-    // some cases.
-    static int skipLws(Reader input) throws IOException {
+    /*
+     *  Skip any whitespace and position to read the next character. The next 
character is returned as being able to
+     *  'peek()' it allows a small optimisation in some cases.
+     */
+    static int skipWhitespace(Reader input) throws IOException {
 
         input.mark(1);
         int c = input.read();
 
-        while (c == 32 || c == 9 || c == 10 || c == 13) {
+        while (c == 32 || c == 9) {
             input.mark(1);
             c = input.read();
         }
@@ -419,7 +420,7 @@ public class HttpParser {
     static SkipResult skipConstant(Reader input, String constant) throws 
IOException {
         int len = constant.length();
 
-        skipLws(input);
+        skipWhitespace(input);
         input.mark(len);
         int c = input.read();
 
@@ -445,7 +446,7 @@ public class HttpParser {
     static String readToken(Reader input) throws IOException {
         StringBuilder result = new StringBuilder();
 
-        skipLws(input);
+        skipWhitespace(input);
         input.mark(1);
         int c = input.read();
 
@@ -472,7 +473,7 @@ public class HttpParser {
     static String readDigits(Reader input) throws IOException {
         StringBuilder result = new StringBuilder();
 
-        skipLws(input);
+        skipWhitespace(input);
         input.mark(1);
         int c = input.read();
 
@@ -520,7 +521,7 @@ public class HttpParser {
      */
     static String readQuotedString(Reader input, boolean returnQuoted) throws 
IOException {
 
-        skipLws(input);
+        skipWhitespace(input);
         int c = input.read();
 
         if (c != '"') {
@@ -557,7 +558,7 @@ public class HttpParser {
     static String readTokenOrQuotedString(Reader input, boolean returnQuoted) 
throws IOException {
 
         // Peek at next character to enable correct method to be called
-        int c = skipLws(input);
+        int c = skipWhitespace(input);
 
         if (c == '"') {
             return readQuotedString(input, returnQuoted);
@@ -580,7 +581,7 @@ public class HttpParser {
         StringBuilder result = new StringBuilder();
         boolean quoted = false;
 
-        skipLws(input);
+        skipWhitespace(input);
         input.mark(1);
         int c = input.read();
 
@@ -633,7 +634,7 @@ public class HttpParser {
         StringBuilder result = new StringBuilder();
         boolean quoted = false;
 
-        skipLws(input);
+        skipWhitespace(input);
         input.mark(1);
         int c = input.read();
 
@@ -677,7 +678,7 @@ public class HttpParser {
     }
 
     static double readWeight(Reader input, char delimiter) throws IOException {
-        skipLws(input);
+        skipWhitespace(input);
         int c = input.read();
         if (c == -1 || c == delimiter) {
             // No q value just whitespace
@@ -688,7 +689,7 @@ public class HttpParser {
             return 0;
         }
         // RFC 7231 does not allow whitespace here but be tolerant
-        skipLws(input);
+        skipWhitespace(input);
         c = input.read();
         if (c != '=') {
             // Malformed. Use quality of zero so it is dropped.
@@ -697,7 +698,7 @@ public class HttpParser {
         }
 
         // RFC 7231 does not allow whitespace here but be tolerant
-        skipLws(input);
+        skipWhitespace(input);
         c = input.read();
 
         // Should be no more than 3 decimal places
@@ -730,7 +731,7 @@ public class HttpParser {
         }
 
         if (c == 9 || c == 32) {
-            skipLws(input);
+            skipWhitespace(input);
             c = input.read();
         }
 
diff --git a/java/org/apache/tomcat/util/http/parser/Upgrade.java 
b/java/org/apache/tomcat/util/http/parser/Upgrade.java
index 60c754ab22..c76aa04245 100644
--- a/java/org/apache/tomcat/util/http/parser/Upgrade.java
+++ b/java/org/apache/tomcat/util/http/parser/Upgrade.java
@@ -69,8 +69,8 @@ public class Upgrade {
                 Reader r = new StringReader(headerValue);
                 SkipResult skipComma;
                 do {
-                    // Skip any leading LWS
-                    HttpParser.skipLws(r);
+                    // Skip any leading whitespace
+                    HttpParser.skipWhitespace(r);
                     String protocolName = HttpParser.readToken(r);
                     if (protocolName == null || protocolName.isEmpty()) {
                         // Invalid
@@ -84,7 +84,7 @@ public class Upgrade {
                             return null;
                         }
                     }
-                    HttpParser.skipLws(r);
+                    HttpParser.skipWhitespace(r);
 
                     skipComma = HttpParser.skipConstant(r, ",");
                     if (skipComma == SkipResult.NOT_FOUND) {
diff --git a/test/org/apache/tomcat/util/http/parser/TestMediaType.java 
b/test/org/apache/tomcat/util/http/parser/TestMediaType.java
index 9a38d1920d..85904cda58 100644
--- a/test/org/apache/tomcat/util/http/parser/TestMediaType.java
+++ b/test/org/apache/tomcat/util/http/parser/TestMediaType.java
@@ -60,9 +60,7 @@ public class TestMediaType {
             new Parameter("charset", CHARSET_QUOTED);
 
 
-    private static final String[] LWS_VALUES = new String[] {
-            "", " ", "\t", "\r", "\n", "\r\n", " \r", " \n", " \r\n",
-            "\r ", "\n ", "\r\n ", " \r ", " \n ", " \r\n " };
+    private static final String[] WHITESPACE = new String[] { "", " ", "\t", " 
\t", "\t " };
 
 
     @Test
@@ -236,7 +234,7 @@ public class TestMediaType {
 
 
     private void doTest(Parameter... parameters) throws IOException {
-        for (String lws : LWS_VALUES) {
+        for (String lws : WHITESPACE) {
             doTest(lws, parameters);
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to