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 d7f8616144ee0f3eaba94bfee73cfd2ca3de8667 Author: Michael Osipov <[email protected]> AuthorDate: Wed Oct 23 15:37:42 2019 +0200 BZ 63835: Add support for Keep-Alive header --- java/org/apache/coyote/http11/Constants.java | 1 + java/org/apache/coyote/http11/Http11Processor.java | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 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 0f24e18..56b6b69 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -915,8 +915,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 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
