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 a5e3e1d7a498a3156350ae8bbed36706b2600e64 Author: Michael Osipov <micha...@apache.org> AuthorDate: Fri Oct 11 12:51:44 2019 +0200 Properly determine requests left on a "keepAlive" connection --- java/org/apache/coyote/http11/Http11Processor.java | 8 +++++++- java/org/apache/tomcat/util/net/SocketWrapperBase.java | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 7bc50a4..314c3d1 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -974,7 +974,13 @@ public class Http11Processor extends AbstractProcessor { String value = "timeout=" + TimeUnit.MILLISECONDS.toSeconds(keepAliveTimeout); if (maxKeepAliveRequests > 0) { - value += ", max=" + maxKeepAliveRequests; + /* + * We need to add 1 here because the value is already decremented in + * service() by 1. Otherwise the client would see 99 on the first request. + * In HTTPd this value is modified after this code block has been run. + */ + int left = socketWrapper.getKeepAliveLeft() + 1; + value += ", max=" + left; } headers.setValue("Keep-Alive").setString(value); diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java b/java/org/apache/tomcat/util/net/SocketWrapperBase.java index 2c082d6..154c9c7 100644 --- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java +++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java @@ -212,12 +212,16 @@ public abstract class SocketWrapperBase<E> { return this.writeTimeout; } + public int getKeepAliveLeft() { + return keepAliveLeft; + } + public void setKeepAliveLeft(int keepAliveLeft) { this.keepAliveLeft = keepAliveLeft; } public int decrementKeepAlive() { - return --keepAliveLeft; + return keepAliveLeft--; } public String getRemoteHost() { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org