You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/10/17 13:47:46 UTC

[tomcat] branch master updated (339f910 -> 11dee21)

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

markt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 339f910  Fix BZ number
     new 101ac39  Refactor Vary parser to the more generic TokenList parser
     new 7c913da  Add a case sensitive / insensitive option to the token list parser
     new 11dee21  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63824

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/coyote/http11/Http11Processor.java | 24 +++++++++--
 java/org/apache/tomcat/util/http/ResponseUtil.java |  4 +-
 .../util/http/parser/{Vary.java => TokenList.java} | 50 +++++++++++++++++++---
 java/org/apache/tomcat/util/http/parser/Vary.java  | 34 +++------------
 .../parser/{TestVary.java => TestTokenList.java}   |  9 +++-
 5 files changed, 78 insertions(+), 43 deletions(-)
 copy java/org/apache/tomcat/util/http/parser/{Vary.java => TokenList.java} (50%)
 rename test/org/apache/tomcat/util/http/parser/{TestVary.java => TestTokenList.java} (93%)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 03/03: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63824

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 11dee21345e32c7ea7581a81900e62c89db65d45
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Oct 17 09:58:41 2019 +0100

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63824
    
    Correctly parse the Connection header when checking to see if the
    "close" option is present.
---
 java/org/apache/coyote/http11/Http11Processor.java | 24 ++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index a176206..80d427f 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -18,9 +18,12 @@ package org.apache.coyote.http11;
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
+import java.io.StringReader;
 import java.nio.ByteBuffer;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Locale;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import javax.servlet.http.HttpServletResponse;
@@ -52,6 +55,7 @@ import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.http.parser.HttpParser;
+import org.apache.tomcat.util.http.parser.TokenList;
 import org.apache.tomcat.util.log.UserDataHelper;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.SSLSupport;
@@ -900,7 +904,7 @@ public class Http11Processor extends AbstractProcessor {
         }
 
         long contentLength = response.getContentLengthLong();
-        boolean connectionClosePresent = false;
+        boolean connectionClosePresent = isConnectionClose(headers);
         if (http11 && response.getTrailerFields() != null) {
             // If trailer fields are set, always use chunking
             outputBuffer.addActiveFilter(outputFilters[Constants.CHUNKED_FILTER]);
@@ -913,7 +917,6 @@ public class Http11Processor extends AbstractProcessor {
         } else {
             // If the response code supports an entity body and we're on
             // HTTP 1.1 then we chunk unless we have a Connection: close header
-            connectionClosePresent = isConnectionClose(headers);
             if (http11 && entityBody && !connectionClosePresent) {
                 outputBuffer.addActiveFilter(outputFilters[Constants.CHUNKED_FILTER]);
                 contentDelimitation = true;
@@ -992,12 +995,25 @@ public class Http11Processor extends AbstractProcessor {
         outputBuffer.commit();
     }
 
-    private static boolean isConnectionClose(MimeHeaders headers) {
+    private static boolean isConnectionClose(MimeHeaders headers) throws IOException {
         MessageBytes connection = headers.getValue(Constants.CONNECTION);
         if (connection == null) {
             return false;
         }
-        return connection.equals(Constants.CLOSE);
+
+        Enumeration<String> values = headers.values(Constants.CONNECTION);
+        Set<String> result = null;
+        while (values.hasMoreElements()) {
+            if (result == null) {
+                result = new HashSet<>();
+            }
+            TokenList.parseTokenList(new StringReader(values.nextElement()), result);
+        }
+
+        if (result == null) {
+            return false;
+        }
+        return result.contains(Constants.CLOSE);
     }
 
     private void prepareSendfile(OutputFilter[] outputFilters) {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/03: Refactor Vary parser to the more generic TokenList parser

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 101ac3947aacc8ded56d69f78090418fa77d8dbb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 16 17:38:53 2019 +0100

    Refactor Vary parser to the more generic TokenList parser
---
 java/org/apache/tomcat/util/http/ResponseUtil.java |  4 +--
 .../util/http/parser/{Vary.java => TokenList.java} | 19 ++++++++----
 java/org/apache/tomcat/util/http/parser/Vary.java  | 34 ++++------------------
 .../parser/{TestVary.java => TestTokenList.java}   |  9 +++++-
 4 files changed, 29 insertions(+), 37 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/ResponseUtil.java b/java/org/apache/tomcat/util/http/ResponseUtil.java
index 025bd49..295e7b7 100644
--- a/java/org/apache/tomcat/util/http/ResponseUtil.java
+++ b/java/org/apache/tomcat/util/http/ResponseUtil.java
@@ -27,7 +27,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.tomcat.util.http.parser.Vary;
+import org.apache.tomcat.util.http.parser.TokenList;
 
 public class ResponseUtil {
 
@@ -81,7 +81,7 @@ public class ResponseUtil {
         for (String varyHeader : varyHeaders) {
             StringReader input = new StringReader(varyHeader);
             try {
-                Vary.parseVary(input, fieldNames);
+                TokenList.parseTokenList(input, fieldNames);
             } catch (IOException ioe) {
                 // Should never happen
             }
diff --git a/java/org/apache/tomcat/util/http/parser/Vary.java b/java/org/apache/tomcat/util/http/parser/TokenList.java
similarity index 78%
copy from java/org/apache/tomcat/util/http/parser/Vary.java
copy to java/org/apache/tomcat/util/http/parser/TokenList.java
index 130ddcf..9ba88b0 100644
--- a/java/org/apache/tomcat/util/http/parser/Vary.java
+++ b/java/org/apache/tomcat/util/http/parser/TokenList.java
@@ -17,18 +17,27 @@
 package org.apache.tomcat.util.http.parser;
 
 import java.io.IOException;
-import java.io.StringReader;
+import java.io.Reader;
+import java.util.Collection;
 import java.util.Locale;
-import java.util.Set;
 
-public class Vary {
+public class TokenList {
 
-    private Vary() {
+    private TokenList() {
         // Utility class. Hide default constructor.
     }
 
 
-    public static void parseVary(StringReader input, Set<String> result) throws IOException {
+    /**
+     * Parses a header of the form 1#token.
+     *
+     * @param input  The header to parse
+     * @param result The Collection (usually a list of a set) to which the
+     *                  parsed token should be added
+     *
+     * @throws IOException If an I/O error occurs reading the header
+     */
+    public static void parseTokenList(Reader input, Collection<String> result) throws IOException {
 
         do {
             String fieldName = HttpParser.readToken(input);
diff --git a/java/org/apache/tomcat/util/http/parser/Vary.java b/java/org/apache/tomcat/util/http/parser/Vary.java
index 130ddcf..e064620 100644
--- a/java/org/apache/tomcat/util/http/parser/Vary.java
+++ b/java/org/apache/tomcat/util/http/parser/Vary.java
@@ -18,9 +18,12 @@ package org.apache.tomcat.util.http.parser;
 
 import java.io.IOException;
 import java.io.StringReader;
-import java.util.Locale;
 import java.util.Set;
 
+/**
+ * @deprecated  Use {@link TokenList}.
+ */
+@Deprecated
 public class Vary {
 
     private Vary() {
@@ -29,33 +32,6 @@ public class Vary {
 
 
     public static void parseVary(StringReader input, Set<String> result) throws IOException {
-
-        do {
-            String fieldName = HttpParser.readToken(input);
-            if (fieldName == null) {
-                // Invalid field-name, skip to the next one
-                HttpParser.skipUntil(input, 0, ',');
-                continue;
-            }
-
-            if (fieldName.length() == 0) {
-                // No more data to read
-                break;
-            }
-
-            SkipResult skipResult = HttpParser.skipConstant(input, ",");
-            if (skipResult == SkipResult.EOF) {
-                // EOF
-                result.add(fieldName.toLowerCase(Locale.ENGLISH));
-                break;
-            } else if (skipResult == SkipResult.FOUND) {
-                result.add(fieldName.toLowerCase(Locale.ENGLISH));
-                continue;
-            } else {
-                // Not a token - ignore it
-                HttpParser.skipUntil(input, 0, ',');
-                continue;
-            }
-        } while (true);
+        TokenList.parseTokenList(input, result);
     }
 }
diff --git a/test/org/apache/tomcat/util/http/parser/TestVary.java b/test/org/apache/tomcat/util/http/parser/TestTokenList.java
similarity index 93%
rename from test/org/apache/tomcat/util/http/parser/TestVary.java
rename to test/org/apache/tomcat/util/http/parser/TestTokenList.java
index ae0bc6a..8405bda 100644
--- a/test/org/apache/tomcat/util/http/parser/TestVary.java
+++ b/test/org/apache/tomcat/util/http/parser/TestTokenList.java
@@ -25,7 +25,7 @@ import java.util.Set;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class TestVary {
+public class TestTokenList {
 
     @Test
     public void testAll() throws IOException {
@@ -125,10 +125,17 @@ public class TestVary {
     }
 
 
+    @SuppressWarnings("deprecation")
     private void doTestVary(String input, Set<String> expected) throws IOException {
         StringReader reader = new StringReader(input);
         Set<String> result = new HashSet<>();
         Vary.parseVary(reader, result);
         Assert.assertEquals(expected, result);
+
+        // Can't use reset(). Parser uses marks.
+        reader = new StringReader(input);
+        result.clear();
+        TokenList.parseTokenList(reader, result);
+        Assert.assertEquals(expected, result);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/03: Add a case sensitive / insensitive option to the token list parser

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7c913da5db338f5976f4ba0dd5dee4c661c1daa6
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 16 17:45:25 2019 +0100

    Add a case sensitive / insensitive option to the token list parser
---
 .../apache/tomcat/util/http/parser/TokenList.java  | 35 +++++++++++++++++++---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/parser/TokenList.java b/java/org/apache/tomcat/util/http/parser/TokenList.java
index 9ba88b0..49e50a5 100644
--- a/java/org/apache/tomcat/util/http/parser/TokenList.java
+++ b/java/org/apache/tomcat/util/http/parser/TokenList.java
@@ -29,15 +29,34 @@ public class TokenList {
 
 
     /**
-     * Parses a header of the form 1#token.
+     * Parses a header of the form 1#token, forcing all parsed values to lower
+     * case. This is typically used when header values are case-insensitive.
      *
      * @param input  The header to parse
      * @param result The Collection (usually a list of a set) to which the
-     *                  parsed token should be added
+     *                   parsed token should be added
      *
      * @throws IOException If an I/O error occurs reading the header
      */
     public static void parseTokenList(Reader input, Collection<String> result) throws IOException {
+        parseTokenList(input, true, result);
+    }
+
+
+    /**
+     * Parses a header of the form 1#token.
+     *
+     * @param input          The header to parse
+     * @param forceLowerCase Should parsed tokens be forced to lower case? This
+     *                           is intended for headers where the values are
+     *                           case-insensitive
+     * @param result         The Collection (usually a list of a set) to which
+     *                           the parsed token should be added
+     *
+     * @throws IOException If an I/O error occurs reading the header
+     */
+    public static void parseTokenList(Reader input, boolean forceLowerCase, Collection<String> result)
+            throws IOException {
 
         do {
             String fieldName = HttpParser.readToken(input);
@@ -55,10 +74,18 @@ public class TokenList {
             SkipResult skipResult = HttpParser.skipConstant(input, ",");
             if (skipResult == SkipResult.EOF) {
                 // EOF
-                result.add(fieldName.toLowerCase(Locale.ENGLISH));
+                if (forceLowerCase) {
+                    result.add(fieldName.toLowerCase(Locale.ENGLISH));
+                } else {
+                    result.add(fieldName);
+                }
                 break;
             } else if (skipResult == SkipResult.FOUND) {
-                result.add(fieldName.toLowerCase(Locale.ENGLISH));
+                if (forceLowerCase) {
+                    result.add(fieldName.toLowerCase(Locale.ENGLISH));
+                } else {
+                    result.add(fieldName);
+                }
                 continue;
             } else {
                 // Not a token - ignore it


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org