Author: remy.maucherat(a)jboss.com
Date: 2014-09-01 09:35:02 -0400 (Mon, 01 Sep 2014)
New Revision: 2497
Modified:
branches/7.5.x/src/main/java/org/apache/coyote/http11/Constants.java
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11AprProcessor.java
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11Processor.java
branches/7.5.x/webapps/docs/sysprops.xml
Log:
BZ1058424: Add support to check for connection: close as included by the web application.
Submitted by Masafumi Miura (ported from Tomcat apparently).
Disabled by default so I am including it, the application should have no business trying
to hack things in the protocol in the first place.
Modified: branches/7.5.x/src/main/java/org/apache/coyote/http11/Constants.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/coyote/http11/Constants.java 2014-08-26
14:30:34 UTC (rev 2496)
+++ branches/7.5.x/src/main/java/org/apache/coyote/http11/Constants.java 2014-09-01
13:35:02 UTC (rev 2497)
@@ -47,6 +47,8 @@
public static final boolean DEFAULT_DISABLE_UPLOAD_TIMEOUT = Boolean.valueOf(
System.getProperty("org.apache.coyote.http11.DEFAULT_DISABLE_UPLOAD_TIMEOUT",
"false"))
.booleanValue();
+ public static final boolean DISABLE_KEEPALIVE_ON_CONCLOSE =
+
Boolean.valueOf(System.getProperty("org.apache.coyote.http11.DISABLE_KEEPALIVE_ON_CONCLOSE",
"false")).booleanValue();
/**
Modified: branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11AprProcessor.java 2014-08-26
14:30:34 UTC (rev 2496)
+++
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11AprProcessor.java 2014-09-01
13:35:02 UTC (rev 2497)
@@ -70,7 +70,6 @@
protected static final boolean CHUNK_ON_CLOSE =
Boolean.valueOf(System.getProperty("org.apache.coyote.http11.Http11Processor.CHUNK_ON_CLOSE",
"false")).booleanValue();
-
// ----------------------------------------------------------- Constructors
@@ -1724,6 +1723,12 @@
}
long contentLength = response.getContentLengthLong();
+ boolean connectionClosePresent = false;
+ if (Constants.DISABLE_KEEPALIVE_ON_CONCLOSE) {
+ connectionClosePresent = isConnectionClose(headers);
+ keepAlive = keepAlive && !connectionClosePresent;
+ }
+
if (contentLength != -1) {
headers.setValue("Content-Length").setLong(contentLength);
outputBuffer.addActiveFilter
@@ -1763,7 +1768,9 @@
// Connection: close header.
keepAlive = keepAlive && !statusDropsConnection(statusCode);
if (!keepAlive) {
- headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ if (!connectionClosePresent) {
+ headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ }
} else if (!http11 && !error) {
headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
}
@@ -1786,6 +1793,13 @@
}
+ private boolean isConnectionClose(MimeHeaders headers) {
+ MessageBytes connection = headers.getValue(Constants.CONNECTION);
+ if (connection == null) {
+ return false;
+ }
+ return connection.equals(Constants.CLOSE);
+ }
/**
* Initialize standard input and output filters.
Modified: branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java 2014-08-26
14:30:34 UTC (rev 2496)
+++
branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java 2014-09-01
13:35:02 UTC (rev 2497)
@@ -1198,6 +1198,12 @@
}
long contentLength = response.getContentLengthLong();
+ boolean connectionClosePresent = false;
+ if (Constants.DISABLE_KEEPALIVE_ON_CONCLOSE) {
+ connectionClosePresent = isConnectionClose(headers);
+ keepAlive = keepAlive && !connectionClosePresent;
+ }
+
if (contentLength != -1) {
headers.setValue("Content-Length").setLong(contentLength);
outputBuffer.addActiveFilter(outputFilters[Constants.IDENTITY_FILTER]);
@@ -1234,7 +1240,9 @@
// Connection: close header.
keepAlive = keepAlive && !statusDropsConnection(statusCode);
if (!keepAlive) {
- headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ if (!connectionClosePresent) {
+ headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ }
} else if (!http11 && !error) {
headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
}
@@ -1257,6 +1265,14 @@
}
+ private boolean isConnectionClose(MimeHeaders headers) {
+ MessageBytes connection = headers.getValue(Constants.CONNECTION);
+ if (connection == null) {
+ return false;
+ }
+ return connection.equals(Constants.CLOSE);
+ }
+
/*
* (non-Javadoc)
*
Modified: branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11Processor.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11Processor.java 2014-08-26
14:30:34 UTC (rev 2496)
+++ branches/7.5.x/src/main/java/org/apache/coyote/http11/Http11Processor.java 2014-09-01
13:35:02 UTC (rev 2497)
@@ -66,7 +66,6 @@
protected static final boolean CHUNK_ON_CLOSE =
Boolean.valueOf(System.getProperty("org.apache.coyote.http11.Http11Processor.CHUNK_ON_CLOSE",
"false")).booleanValue();
-
// ------------------------------------------------------------ Constructor
@@ -1565,6 +1564,12 @@
}
long contentLength = response.getContentLengthLong();
+ boolean connectionClosePresent = false;
+ if (Constants.DISABLE_KEEPALIVE_ON_CONCLOSE) {
+ connectionClosePresent = isConnectionClose(headers);
+ keepAlive = keepAlive && !connectionClosePresent;
+ }
+
if (contentLength != -1) {
headers.setValue("Content-Length").setLong(contentLength);
outputBuffer.addActiveFilter
@@ -1604,7 +1609,9 @@
// Connection: close header.
keepAlive = keepAlive && !statusDropsConnection(statusCode);
if (!keepAlive) {
- headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ if (!connectionClosePresent) {
+ headers.addValue(Constants.CONNECTION).setString(Constants.CLOSE);
+ }
} else if (!http11 && !error) {
headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
}
@@ -1627,6 +1634,13 @@
}
+ private boolean isConnectionClose(MimeHeaders headers) {
+ MessageBytes connection = headers.getValue(Constants.CONNECTION);
+ if (connection == null) {
+ return false;
+ }
+ return connection.equals(Constants.CLOSE);
+ }
/**
* Initialize standard input and output filters.
Modified: branches/7.5.x/webapps/docs/sysprops.xml
===================================================================
--- branches/7.5.x/webapps/docs/sysprops.xml 2014-08-26 14:30:34 UTC (rev 2496)
+++ branches/7.5.x/webapps/docs/sysprops.xml 2014-09-01 13:35:02 UTC (rev 2497)
@@ -189,6 +189,11 @@
which means it will use the default socket timeout.</p>
</property>
+ <property
name="org.apache.coyote.http11.DISABLE_KEEPALIVE_ON_CONCLOSE">
+ <p>If a <code>connection:close header</code> is included in the
response by the
+ application, disable keep alive. The default value is
<code>false</code>.</p>
+ </property>
+
</properties>
</section>
Show replies by date