diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java index 66d9806fc90..6bdbae7be25 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java @@ -527,7 +527,7 @@ public class ProxyServlet implements Servlet if (ex instanceof EofException) { _log.ignore(ex); - return; + //return; } handleOnException(ex,request,response); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java index 503a64e47c4..fd1ccd3fe4b 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java @@ -18,19 +18,6 @@ package org.eclipse.jetty.servlets; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.MalformedURLException; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import junit.framework.Assert; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; @@ -45,11 +32,24 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.hamcrest.core.Is; +import org.hamcrest.core.IsEqual; import org.junit.After; import org.junit.Test; -import static org.junit.Assert.*; -import static org.hamcrest.Matchers.*; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; public class ProxyServletTest { @@ -190,4 +190,53 @@ public class ProxyServletTest long rate = file.length() / 1024 * 1000 / millis; System.out.printf("download rate = %d KiB/s%n", rate); } + + @Test + public void testLessContentThanContentLength() throws Exception { + init(new HttpServlet() { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + byte[] message = "tooshort".getBytes("ascii"); + resp.setContentType("text/plain;charset=ascii"); + resp.setHeader("Content-Length", Long.toString(message.length+1)); + resp.getOutputStream().write(message); + } + }); + + final AtomicBoolean excepted = new AtomicBoolean(false); + + ContentExchange exchange = new ContentExchange(true) + { + @Override + protected void onResponseContent(Buffer content) throws IOException + { + try + { + // Slow down the reader + TimeUnit.MILLISECONDS.sleep(10); + super.onResponseContent(content); + } + catch (InterruptedException x) + { + throw (IOException)new IOException().initCause(x); + } + } + + @Override + protected void onException(Throwable x) + { + excepted.set(true); + super.onException(x); + } + + + }; + + String url = "http://localhost:" + _connector.getLocalPort() + "/proxy/test"; + exchange.setURL(url); + + _client.send(exchange); + exchange.waitForDone(); + assertThat(excepted.get(),equalTo(true)); + } }