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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org