Author: markt
Date: Wed May 28 13:17:04 2014
New Revision: 1598007
URL: http://svn.apache.org/r1598007
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56555
When Tomcat closes the connection based on the HTTP status code of the
response, ensure that only one connection header is sent to the client.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1597987
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1598007&r1=1598006&r2=1598007&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
Wed May 28 13:17:04 2014
@@ -1514,11 +1514,8 @@ public abstract class AbstractHttp11Proc
// Connection: close header.
keepAlive = keepAlive && !statusDropsConnection(statusCode);
if (!keepAlive) {
- // Avoid adding the close header twice
- if (!connectionClosePresent) {
- headers.addValue(Constants.CONNECTION).setString(
- Constants.CLOSE);
- }
+ headers.setValue(Constants.CONNECTION).setString(
+ Constants.CLOSE);
} else if (!http11 && !error) {
headers.addValue(Constants.CONNECTION).setString(Constants.KEEPALIVE);
}
Modified:
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java?rev=1598007&r1=1598006&r2=1598007&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
(original)
+++
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
Wed May 28 13:17:04 2014
@@ -25,6 +25,7 @@ import java.net.Socket;
import java.nio.CharBuffer;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@@ -53,6 +54,45 @@ import org.apache.tomcat.util.buf.ByteCh
public class TestAbstractHttp11Processor extends TomcatBaseTest {
@Test
+ public void testStatusForcesClose() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // Must have a real docBase - just use temp
+ Context ctxt = tomcat.addContext("",
System.getProperty("java.io.tmpdir"));
+
+ // Add protected servlet
+ Tomcat.addServlet(ctxt, "StatusForcesCloseServlet", new
StatusForcesCloseServlet());
+ ctxt.addServletMapping("/*", "StatusForcesCloseServlet");
+
+ tomcat.start();
+
+ ByteChunk bc = new ByteChunk();
+ Map<String,List<String>> responseHeaders = new
HashMap<String,List<String>>();
+ getUrl("http://localhost:" + getPort() + "/anything", bc,
responseHeaders);
+
+ // Assumes header name uses standard case
+ List<String> values = responseHeaders.get("Connection");
+ Assert.assertEquals(1, values.size());
+ Assert.assertEquals("close",
values.get(0).toLowerCase(Locale.ENGLISH));
+ }
+
+ private static class StatusForcesCloseServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ // Set the Connection header
+ resp.setHeader("Connection", "keep-alive");
+
+ // Set a status code that should force the connection to close
+ resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ }
+ }
+
+ @Test
public void testWithTEVoid() throws Exception {
Tomcat tomcat = getTomcatInstance();
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1598007&r1=1598006&r2=1598007&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed May 28 13:17:04 2014
@@ -88,6 +88,11 @@
buffer when the buffer is only partially written on a subsequent write.
(markt)
</fix>
+ <fix>
+ <bug>56555</bug>: When Tomcat closes the connection based on the HTTP
+ status code of the response, ensure that only one connection header is
+ sent to the client. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]