Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-12-02 01:40:04 +0000
committerGreg Wilkins2015-12-02 01:40:04 +0000
commit49f7a2f0e21a3eaa6ecb4801fe908fa8343917d9 (patch)
tree2cdba2cfdf0c93e822c794d9c2856f01bfee7ece
parent3962fe010a44bb09d33fab1fcddd92e8675efb46 (diff)
downloadorg.eclipse.jetty.project-49f7a2f0e21a3eaa6ecb4801fe908fa8343917d9.tar.gz
org.eclipse.jetty.project-49f7a2f0e21a3eaa6ecb4801fe908fa8343917d9.tar.xz
org.eclipse.jetty.project-49f7a2f0e21a3eaa6ecb4801fe908fa8343917d9.zip
483422 - Empty chunked body in 304 Response
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java69
2 files changed, 73 insertions, 1 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java
index f34544cc82..2488fab060 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java
@@ -660,8 +660,11 @@ public class HttpGenerator extends AbstractGenerator
// written yet?
// Response known not to have a body
- if (_contentWritten == 0 && isResponse() && (_status < 200 || _status == 204 || _status == 304))
+ if (isResponse() && _noContent)
+ {
_contentLength = HttpTokens.NO_CONTENT;
+ _contentWritten=0;
+ }
else if (_last)
{
// we have seen all the _content there is
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
index 8e78dcd320..6b4c5c3788 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -50,8 +51,10 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat;
@@ -1384,6 +1387,72 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
}
+
+ @Test
+ public void testWriteBodyAfterNoBodyREsponse() throws Exception
+ {
+ configureServer(new WriteBodyAfterNoBodyResponseHandler());
+ Socket client=newSocket(HOST,_connector.getLocalPort());
+ final OutputStream out=client.getOutputStream();
+
+ out.write("GET / HTTP/1.1\r\nHost: test\r\n\r\n".getBytes());
+ out.write("GET / HTTP/1.1\r\nHost: test\r\nConnection: close\r\n\r\n".getBytes());
+ out.flush();
+
+
+ BufferedReader in =new BufferedReader(new InputStreamReader(client.getInputStream()));
+
+ String line=in.readLine();
+ assertThat(line, containsString(" 304 "));
+ while (true)
+ {
+ line=in.readLine();
+ if (line==null)
+ throw new EOFException();
+ if (line.length()==0)
+ break;
+
+ assertThat(line, not(containsString("Content-Length")));
+ assertThat(line, not(containsString("Content-Type")));
+ assertThat(line, not(containsString("Transfer-Encoding")));
+ }
+
+ line=in.readLine();
+ assertThat(line, containsString(" 304 "));
+ while (true)
+ {
+ line=in.readLine();
+ if (line==null)
+ throw new EOFException();
+ if (line.length()==0)
+ break;
+
+ assertThat(line, not(containsString("Content-Length")));
+ assertThat(line, not(containsString("Content-Type")));
+ assertThat(line, not(containsString("Transfer-Encoding")));
+ }
+
+ do
+ {
+ line=in.readLine();
+ }
+ while (line!=null);
+
+ }
+
+ private class WriteBodyAfterNoBodyResponseHandler extends AbstractHandler
+ {
+ @Override
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ baseRequest.setHandled(true);
+ response.setStatus(304);
+ response.getOutputStream().print("yuck");
+ response.flushBuffer();
+ }
+ }
+
+
public class NoopHandler extends AbstractHandler
{
public void handle(String target, Request baseRequest,

Back to the top