You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mi...@apache.org on 2019/11/10 00:23:19 UTC

[tomcat] branch BZ-63835/9.0.x updated (d7f8616 -> bf3f951)

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

michaelo pushed a change to branch BZ-63835/9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    omit d7f8616  BZ 63835: Add support for Keep-Alive header
     add 1638e4f  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63838
     add 6bc2615  63879: Remove stack trace from debug logging on socket wrapper close
     add b3a8e01  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63864
     add 4637304  Remove unnecessary code
     add 49d37df  Move connection tracking to the endpoint
     add 6c255a1  Avoid API change
     add 7eb93de  Add missing i18n
     add 99952af  Log tweaks
     add 6626089  Correct description of default value of server attribute
     add 6064cd7  Remove unnecessary changes to fix BZ 63836
     add 7c74df7  Polish. Improve alignment with 8.5.x/7.0.x
     add 782979f  Add @Deprecated to fix IDE warning
     add fd31ffe  Fix Javadoc error (only need <pre>, not <code> as well)
     add f16ae27  Remove unused code
     add 65abaf3  Refactor to (slightly) reduce native calls when using OpenSSL
     add 2c999ef  OpenSSLEngine to differentiate between optional and optionalNoCA
     add 066e254  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63897 JSP timestamps
     add 5e9f6fd  Fix a possible race condition
     add 09a383c  Fix credit
     add 17dc9cc  Reformat comment
     add b351ed7  Correct entry so it makes sense
     add 4945083  Remove connections map from APR endpoint
     add eb1d0e8  Update to CXF 3.3.4
     add 785becd  Remove duplicate put operation
     add ae8f518  Fix IDE warning
     add 2a9b0fe  Fix typo
     add e765a4d  Expand coverage of French translations
     add a8defb1  Fix typos in Japanese translations.
     add 47de9b2  Expand coverage and quality of Simplified Chinese translations
     add 7dca58a  Remove unnecessary trailing space
     add 8dc6c1f  Expand coverage and quality of Brazilian Portuguese translations
     add 2f4e1f2  Fix PR #211 via POEditor
     add 8ce7933  Fix typo
     add 31ebf2f  Fix typo
     add d8e336d  Fix typo
     add d3b4844  Remove redundant method for clean
     add f7e2dce  Move count down connections to the shared close
     add 5f4d5b3  Better cleanup in setSocketOptions
     add 03e7bc8  Fix JSP compilation showing old content reported on users@ list
     add b12f3b1  Follow on to 03e7bc84
     add 67909e0  Add comment to explain the cleanup
     add ffb553c  Fix logic that meant AJP was not always non-blocking between requests
     add 58898a5  Polish
     add 69602cb  BZ 63905: Clean up Tomcat CSS
     add ccd6518  Fix test fallout of BZ 63905
     new bf3f951  BZ 63835: Add support for Keep-Alive header

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d7f8616)
            \
             N -- N -- N   refs/heads/BZ-63835/9.0.x (bf3f951)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 build.xml                                          |  18 +++
 java/javax/el/LocalStrings_pt_BR.properties        |   5 +
 java/javax/el/LocalStrings_zh_CN.properties        |   4 +-
 java/javax/servlet/AsyncContext.java               |   2 +-
 java/javax/servlet/LocalStrings_zh_CN.properties   |   3 +
 .../servlet/http/LocalStrings_zh_CN.properties     |   1 +
 .../authenticator/LocalStrings_zh_CN.properties    |   7 ++
 .../jaspic/LocalStrings_zh_CN.properties           |   1 +
 .../connector/LocalStrings_zh_CN.properties        |   9 ++
 .../catalina/core/LocalStrings_zh_CN.properties    |  33 +++++
 .../apache/catalina/core/StandardWrapperValve.java |   1 -
 .../catalina/filters/LocalStrings_zh_CN.properties |  19 ++-
 .../backend}/LocalStrings_zh_CN.properties         |   2 +-
 .../ha/deploy/LocalStrings_zh_CN.properties        |   3 +
 .../ha/session/LocalStrings_zh_CN.properties       |  10 ++
 .../catalina/loader/LocalStrings_zh_CN.properties  |   5 +
 .../catalina/mapper/LocalStrings_zh_CN.properties  |   3 +
 .../catalina/mbeans/LocalStrings_zh_CN.properties  |   2 +
 .../catalina/realm/LocalStrings_zh_CN.properties   |   9 ++
 .../apache/catalina/servlets/DefaultServlet.java   |  16 ++-
 .../servlets/LocalStrings_zh_CN.properties         |   2 +
 .../catalina/session/LocalStrings_zh_CN.properties |  10 ++
 .../LocalStrings_zh_CN.properties                  |   2 +-
 .../org/apache/catalina/startup/ContextConfig.java |  11 +-
 .../catalina/startup/LocalStrings_zh_CN.properties |  15 +++
 .../storeconfig/LocalStrings_zh_CN.properties      |   7 ++
 .../apache/catalina/tribes/group/GroupChannel.java |   2 +-
 .../tribes/group/LocalStrings_zh_CN.properties     |   4 +
 .../interceptors/LocalStrings_zh_CN.properties     |   4 +
 .../membership/LocalStrings_zh_CN.properties       |  12 +-
 .../tribes/tipis/LocalStrings_zh_CN.properties     |   6 +
 .../catalina/tribes/transport/ReceiverBase.java    |  10 +-
 .../transport/bio/LocalStrings_pt_BR.properties    |   2 +
 .../transport/bio/LocalStrings_zh_CN.properties    |   4 +
 .../transport/nio/LocalStrings_zh_CN.properties    |   5 +
 .../tribes/util/LocalStrings_zh_CN.properties      |   1 +
 .../catalina/util/LocalStrings_pt_BR.properties    |   2 +-
 .../catalina/util/LocalStrings_zh_CN.properties    |   6 +
 java/org/apache/catalina/util/TomcatCSS.java       |  16 ++-
 .../catalina/valves/LocalStrings_zh_CN.properties  |  16 +++
 .../rewrite}/LocalStrings_zh_CN.properties         |   2 +-
 .../apache/catalina/valves/rewrite/RewriteMap.java |   2 -
 .../catalina/webresources/CachedResource.java      | 126 ++++++++++++++++++-
 .../catalina/webresources/LocalStrings.properties  |   2 +
 .../webresources/LocalStrings_zh_CN.properties     |   7 ++
 .../apache/catalina/webresources/StandardRoot.java |   2 +-
 java/org/apache/coyote/AbstractProtocol.java       |  48 ++++---
 java/org/apache/coyote/LocalStrings.properties     |   4 +-
 .../apache/coyote/LocalStrings_zh_CN.properties    |   3 +
 java/org/apache/coyote/ajp/AjpProcessor.java       |   8 +-
 .../coyote/ajp/LocalStrings_zh_CN.properties       |   1 +
 java/org/apache/coyote/http11/Http11Processor.java |  24 ++--
 .../coyote/http11/LocalStrings_zh_CN.properties    |   5 +
 .../http11/filters/LocalStrings_zh_CN.properties   |   1 +
 .../http11/upgrade/LocalStrings_zh_CN.properties   |   4 +
 .../coyote/http2/LocalStrings_zh_CN.properties     |  18 +++
 java/org/apache/jasper/JspCompilationContext.java  |   4 +-
 java/org/apache/jasper/compiler/Compiler.java      |   2 +-
 java/org/apache/jasper/compiler/Generator.java     |  18 ++-
 .../jasper/resources/LocalStrings_zh_CN.properties |  25 ++++
 .../apache/naming/LocalStrings_zh_CN.properties    |   4 +
 .../naming/factory/LocalStrings_zh_CN.properties   |   5 +
 .../tomcat/util/LocalStrings_zh_CN.properties      |   1 +
 .../tomcat/util/buf/LocalStrings_zh_CN.properties  |   5 +
 java/org/apache/tomcat/util/buf/package.html       |   2 +-
 .../tomcat/util/compat/LocalStrings_fr.properties  |   2 +
 .../util/compat/LocalStrings_zh_CN.properties      |   2 +
 .../util/descriptor}/LocalStrings_zh_CN.properties |   2 +-
 .../descriptor/web/LocalStrings_zh_CN.properties   |  10 ++
 .../util/digester/LocalStrings_ja.properties       |   4 +-
 .../util/digester/LocalStrings_zh_CN.properties    |   2 +-
 .../tomcat/util/http/LocalStrings_zh_CN.properties |   5 +
 .../util/http/parser/LocalStrings_zh_CN.properties |   3 +
 .../util/json}/LocalStrings_zh_CN.properties       |   2 +-
 .../apache/tomcat/util/net/AbstractEndpoint.java   |  18 +++
 .../tomcat/util/net/AbstractJsseEndpoint.java      |  28 ++---
 java/org/apache/tomcat/util/net/AprEndpoint.java   |  31 +++--
 .../tomcat/util/net/LocalStrings_zh_CN.properties  |  19 ++-
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  26 ++--
 java/org/apache/tomcat/util/net/NioEndpoint.java   |  19 +--
 .../apache/tomcat/util/net/SocketWrapperBase.java  |  15 ++-
 .../util/net/jsse/LocalStrings_zh_CN.properties    |   1 +
 .../util/net/openssl/LocalStrings_zh_CN.properties |   3 +
 .../tomcat/util/net/openssl/OpenSSLContext.java    |   5 +-
 .../tomcat/util/net/openssl/OpenSSLEngine.java     |  37 +++---
 .../tomcat/util/scan/LocalStrings_zh_CN.properties |   1 +
 .../tomcat/websocket/LocalStrings_zh_CN.properties |  17 +++
 .../websocket/pojo/LocalStrings_zh_CN.properties   |   6 +
 .../websocket/server/LocalStrings_zh_CN.properties |   5 +
 modules/cxf/pom.xml                                |   2 +-
 .../apache/catalina/startup/SimpleHttpClient.java  |   7 +-
 .../apache/coyote/http11/TestHttp11Processor.java  | 140 ++++++++++++++++++---
 .../coyote/http2/TestHttp2InitialConnection.java   |   2 +-
 webapps/docs/changelog.xml                         |  86 +++++++++++++
 webapps/docs/config/valve.xml                      |   5 +-
 webapps/docs/security-howto.xml                    |   5 +-
 .../WEB-INF/classes/LocalStrings_zh_CN.properties  |   1 +
 97 files changed, 933 insertions(+), 191 deletions(-)
 copy java/org/apache/catalina/{storeconfig => ha/backend}/LocalStrings_zh_CN.properties (93%)
 copy java/org/apache/catalina/{storeconfig => ssi}/LocalStrings_zh_CN.properties (93%)
 copy java/org/apache/catalina/{storeconfig => valves/rewrite}/LocalStrings_zh_CN.properties (93%)
 copy java/org/apache/{catalina/ha/authenticator => tomcat/util/descriptor}/LocalStrings_zh_CN.properties (86%)
 copy java/org/apache/{catalina/storeconfig => tomcat/util/json}/LocalStrings_zh_CN.properties (92%)


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


[tomcat] 01/01: BZ 63835: Add support for Keep-Alive header

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

michaelo pushed a commit to branch BZ-63835/9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit bf3f9515495476d480765c183a3442d8e3d5f129
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Oct 23 15:37:42 2019 +0200

    BZ 63835: Add support for Keep-Alive header
    
    This implementation slightly varies from HTTPd in way that it responds with
    'Connection: keep-alive' if and only if additionally to the required request
    header the keepAliveTimeout has to be greater than 0.
    
    Also modified existing tests because HttpUrlConnection always sends
    'Connection: keep-alive' where the tests are not aware of this thus fail.
---
 java/org/apache/coyote/http11/Constants.java       |   1 +
 java/org/apache/coyote/http11/Http11Processor.java |  22 +++-
 .../apache/catalina/startup/SimpleHttpClient.java  |   7 +-
 .../apache/coyote/http11/TestHttp11Processor.java  | 140 ++++++++++++++++++---
 4 files changed, 152 insertions(+), 18 deletions(-)

diff --git a/java/org/apache/coyote/http11/Constants.java b/java/org/apache/coyote/http11/Constants.java
index 2ca4dc4..55045d4 100644
--- a/java/org/apache/coyote/http11/Constants.java
+++ b/java/org/apache/coyote/http11/Constants.java
@@ -117,6 +117,7 @@ public final class Constants {
     public static final String CHUNKED = "chunked";
     public static final byte[] ACK_BYTES = ByteChunk.convertToBytes("HTTP/1.1 100 " + CRLF + CRLF);
     public static final String TRANSFERENCODING = "Transfer-Encoding";
+    public static final String KEEP_ALIVE = "Keep-Alive";
     public static final byte[] _200_BYTES = ByteChunk.convertToBytes("200");
     public static final byte[] _400_BYTES = ByteChunk.convertToBytes("400");
     public static final byte[] _404_BYTES = ByteChunk.convertToBytes("404");
diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index 6ffcd16..4698174 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -907,8 +907,26 @@ public class Http11Processor extends AbstractProcessor {
                 headers.addValue(Constants.CONNECTION).setString(
                         Constants.CLOSE);
             }
-        } else if (!http11 && !getErrorState().isError()) {
-            headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
+        } else if (!getErrorState().isError()) {
+            if (!http11) {
+                headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
+            }
+
+            boolean connectionKeepAlivePresent =
+                isConnectionToken(request.getMimeHeaders(), Constants.KEEPALIVE);
+
+            if (connectionKeepAlivePresent) {
+                int keepAliveTimeout = protocol.getKeepAliveTimeout();
+
+                if (keepAliveTimeout > 0) {
+                    String value = "timeout=" + keepAliveTimeout / 1000L;
+                    headers.setValue(Constants.KEEP_ALIVE).setString(value);
+
+                    if (http11) {
+                        headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
+                    }
+                }
+            }
         }
 
         // Add server header
diff --git a/test/org/apache/catalina/startup/SimpleHttpClient.java b/test/org/apache/catalina/startup/SimpleHttpClient.java
index b53bb1a..6ff2050 100644
--- a/test/org/apache/catalina/startup/SimpleHttpClient.java
+++ b/test/org/apache/catalina/startup/SimpleHttpClient.java
@@ -56,6 +56,7 @@ public abstract class SimpleHttpClient {
     public static final String REDIRECT_302 = "HTTP/1.1 302 ";
     public static final String REDIRECT_303 = "HTTP/1.1 303 ";
     public static final String FAIL_400 = "HTTP/1.1 400 ";
+    public static final String FORBIDDEN_403 = "HTTP/1.1 403 ";
     public static final String FAIL_404 = "HTTP/1.1 404 ";
     public static final String FAIL_405 = "HTTP/1.1 405 ";
     public static final String TIMEOUT_408 = "HTTP/1.1 408 ";
@@ -444,6 +445,10 @@ public abstract class SimpleHttpClient {
         return responseLineStartsWith(FAIL_400);
     }
 
+    public boolean isResponse403() {
+        return responseLineStartsWith(FORBIDDEN_403);
+    }
+
     public boolean isResponse404() {
         return responseLineStartsWith(FAIL_404);
     }
@@ -481,4 +486,4 @@ public abstract class SimpleHttpClient {
     }
 
     public abstract boolean isResponseBodyOK();
-}
\ No newline at end of file
+}
diff --git a/test/org/apache/coyote/http11/TestHttp11Processor.java b/test/org/apache/coyote/http11/TestHttp11Processor.java
index 7febf50..8923b9b 100644
--- a/test/org/apache/coyote/http11/TestHttp11Processor.java
+++ b/test/org/apache/coyote/http11/TestHttp11Processor.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Reader;
+import java.io.StringReader;
 import java.io.Writer;
 import java.net.InetSocketAddress;
 import java.net.Socket;
@@ -33,7 +34,6 @@ import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 
@@ -58,6 +58,7 @@ import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.descriptor.web.SecurityCollection;
 import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
+import org.apache.tomcat.util.http.parser.TokenList;
 
 public class TestHttp11Processor extends TomcatBaseTest {
 
@@ -575,26 +576,37 @@ public class TestHttp11Processor extends TomcatBaseTest {
 
         tomcat.start();
 
-        byte[] requestBody = "HelloWorld".getBytes(StandardCharsets.UTF_8);
-        Map<String,List<String>> reqHeaders = null;
+        String request =
+                "POST /echo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: localhost:" + getPort() + SimpleHttpClient.CRLF;
         if (useExpectation) {
-            reqHeaders = new HashMap<>();
-            List<String> expectation = new ArrayList<>();
-            expectation.add("100-continue");
-            reqHeaders.put("Expect", expectation);
+            request += "Expect: 100-continue" + SimpleHttpClient.CRLF;
+        }
+        request += SimpleHttpClient.CRLF +
+                   "HelloWorld";
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        Assert.assertTrue(client.isResponse403());
+        String connectionHeaderValue = null;
+        for (String header : client.getResponseHeaders()) {
+            if (header.startsWith("Connection:")) {
+                connectionHeaderValue = header.substring(header.indexOf(':') + 1).trim();
+                break;
+            }
         }
-        ByteChunk responseBody = new ByteChunk();
-        Map<String,List<String>> responseHeaders = new HashMap<>();
-        int rc = postUrl(requestBody, "http://localhost:" + getPort() + "/echo",
-                responseBody, reqHeaders, responseHeaders);
 
-        Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN, rc);
-        List<String> connectionHeaders = responseHeaders.get("Connection");
         if (useExpectation) {
+            List<String> connectionHeaders = new ArrayList<>();
+            TokenList.parseTokenList(new StringReader(connectionHeaderValue), connectionHeaders);
             Assert.assertEquals(1, connectionHeaders.size());
-            Assert.assertEquals("close", connectionHeaders.get(0).toLowerCase(Locale.ENGLISH));
+            Assert.assertEquals("close", connectionHeaders.get(0));
         } else {
-            Assert.assertNull(connectionHeaders);
+            Assert.assertNull(connectionHeaderValue);
         }
     }
 
@@ -1503,6 +1515,104 @@ public class TestHttp11Processor extends TomcatBaseTest {
     }
 
 
+    @Test
+    public void testKeepAliveHeader01() throws Exception {
+        doTestKeepAliveHeader(false, 3000, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader02() throws Exception {
+        doTestKeepAliveHeader(true, 5000, 1);
+    }
+
+    @Test
+    public void testKeepAliveHeader03() throws Exception {
+        doTestKeepAliveHeader(true, 5000, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader04() throws Exception {
+        doTestKeepAliveHeader(true, -1, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader05() throws Exception {
+        doTestKeepAliveHeader(true, -1, 1);
+    }
+
+    @Test
+    public void testKeepAliveHeader06() throws Exception {
+        doTestKeepAliveHeader(true, -1, -1);
+    }
+
+    public void doTestKeepAliveHeader(boolean sendKeepAlive, int keepAliveTimeout, int maxKeepAliveRequests) throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        tomcat.getConnector().setAttribute("keepAliveTimeout", keepAliveTimeout);
+        tomcat.getConnector().setAttribute("maxKeepAliveRequests", maxKeepAliveRequests);
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMappingDecoded("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: localhost:" + getPort() + SimpleHttpClient.CRLF;
+
+        if (sendKeepAlive) {
+            request += "Connection: keep-alive" + SimpleHttpClient.CRLF;
+        }
+
+        request += SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest(false);
+
+        Assert.assertTrue(client.isResponse200());
+
+        String connectionHeaderValue = null;
+        String keepAliveHeaderValue = null;
+        for (String header : client.getResponseHeaders()) {
+            if (header.startsWith("Connection:")) {
+                connectionHeaderValue = header.substring(header.indexOf(':') + 1).trim();
+            }
+            if (header.startsWith("Keep-Alive:")) {
+                keepAliveHeaderValue = header.substring(header.indexOf(':') + 1).trim();
+            }
+        }
+
+        if (!sendKeepAlive || keepAliveTimeout < 0
+            && (maxKeepAliveRequests < 0 || maxKeepAliveRequests > 1)) {
+            Assert.assertNull(connectionHeaderValue);
+            Assert.assertNull(keepAliveHeaderValue);
+        } else {
+            List<String> connectionHeaders = new ArrayList<>();
+            TokenList.parseTokenList(new StringReader(connectionHeaderValue), connectionHeaders);
+
+            if (sendKeepAlive && keepAliveTimeout > 0 &&
+                (maxKeepAliveRequests < 0 || maxKeepAliveRequests > 1)) {
+                Assert.assertEquals(1, connectionHeaders.size());
+                Assert.assertEquals("keep-alive", connectionHeaders.get(0));
+                Assert.assertEquals("timeout=" + keepAliveTimeout / 1000L, keepAliveHeaderValue);
+            }
+
+            if (sendKeepAlive && maxKeepAliveRequests == 1) {
+                Assert.assertEquals(1, connectionHeaders.size());
+                Assert.assertEquals("close", connectionHeaders.get(0));
+                Assert.assertNull(keepAliveHeaderValue);
+            }
+        }
+    }
+
+
     /**
      * Test servlet that prints out the values of
      * HttpServletRequest.getServerName() and


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