Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-07-03 21:15:39 -0400
committerJan Bartel2013-07-03 21:15:39 -0400
commit8aac3eef4824e1db84c708f31e88f25989145bc8 (patch)
treeee7fcee8009c1361194b743afa8738955014d531 /jetty-servlets/src
parentc934bbe45ca7da07f0c39129c4d64b1dc00042dc (diff)
parent091a4195686ad6b429d7170990e97a290d3a24bf (diff)
downloadorg.eclipse.jetty.project-8aac3eef4824e1db84c708f31e88f25989145bc8.tar.gz
org.eclipse.jetty.project-8aac3eef4824e1db84c708f31e88f25989145bc8.tar.xz
org.eclipse.jetty.project-8aac3eef4824e1db84c708f31e88f25989145bc8.zip
Merge remote-tracking branch 'origin/jetty-7' into jetty-8
Conflicts: jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
Diffstat (limited to 'jetty-servlets/src')
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java4
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java23
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWriteWithFlush.java72
3 files changed, 89 insertions, 10 deletions
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
index 8834aa688c..a84349eca8 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.servlets;
import java.io.File;
import java.util.Arrays;
import java.util.List;
+
import javax.servlet.Servlet;
import org.eclipse.jetty.http.HttpStatus;
@@ -30,6 +31,7 @@ import org.eclipse.jetty.servlets.gzip.GzipTester;
import org.eclipse.jetty.servlets.gzip.TestServletLengthStreamTypeWrite;
import org.eclipse.jetty.servlets.gzip.TestServletLengthTypeStreamWrite;
import org.eclipse.jetty.servlets.gzip.TestServletStreamLengthTypeWrite;
+import org.eclipse.jetty.servlets.gzip.TestServletStreamLengthTypeWriteWithFlush;
import org.eclipse.jetty.servlets.gzip.TestServletStreamTypeLengthWrite;
import org.eclipse.jetty.servlets.gzip.TestServletTypeLengthStreamWrite;
import org.eclipse.jetty.servlets.gzip.TestServletTypeStreamLengthWrite;
@@ -72,12 +74,14 @@ public class GzipFilterContentLengthTest
{ TestServletLengthStreamTypeWrite.class, GzipFilter.GZIP },
{ TestServletLengthTypeStreamWrite.class, GzipFilter.GZIP },
{ TestServletStreamLengthTypeWrite.class, GzipFilter.GZIP },
+ { TestServletStreamLengthTypeWriteWithFlush.class, GzipFilter.GZIP },
{ TestServletStreamTypeLengthWrite.class, GzipFilter.GZIP },
{ TestServletTypeLengthStreamWrite.class, GzipFilter.GZIP },
{ TestServletTypeStreamLengthWrite.class, GzipFilter.GZIP },
{ TestServletLengthStreamTypeWrite.class, GzipFilter.DEFLATE },
{ TestServletLengthTypeStreamWrite.class, GzipFilter.DEFLATE },
{ TestServletStreamLengthTypeWrite.class, GzipFilter.DEFLATE },
+ { TestServletStreamLengthTypeWriteWithFlush.class, GzipFilter.DEFLATE },
{ TestServletStreamTypeLengthWrite.class, GzipFilter.DEFLATE },
{ TestServletTypeLengthStreamWrite.class, GzipFilter.DEFLATE },
{ TestServletTypeStreamLengthWrite.class, GzipFilter.DEFLATE }
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
index 5129d0d80e..e0ded0b262 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
@@ -18,13 +18,8 @@
package org.eclipse.jetty.servlets.gzip;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -58,7 +53,6 @@ import org.eclipse.jetty.testing.ServletTester;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir;
-import org.eclipse.jetty.util.DateCache;
import org.hamcrest.Matchers;
import org.junit.Assert;
@@ -118,8 +112,17 @@ public class GzipTester
// Assert the response headers
Assert.assertThat("Response.method",response.getMethod(),nullValue());
- // Assert.assertThat("Response.status",response.getStatus(),is(HttpServletResponse.SC_OK));
- Assert.assertThat("Response.header[Content-Length]",response.getHeader("Content-Length"),notNullValue());
+
+ // Response headers should have either a Transfer-Encoding indicating chunked OR a Content-Length
+ String contentLength = response.getHeader("Content-Length");
+ String transferEncoding = response.getHeader("Transfer-Encoding");
+ boolean chunked = (transferEncoding != null) && (transferEncoding.indexOf("chunk") >= 0);
+ if(!chunked) {
+ Assert.assertThat("Response.header[Content-Length]",contentLength,notNullValue());
+ } else {
+ Assert.assertThat("Response.header[Transfer-Encoding]",transferEncoding,notNullValue());
+ }
+
int qindex = compressionType.indexOf(";");
if (qindex < 0)
Assert.assertThat("Response.header[Content-Encoding]",response.getHeader("Content-Encoding"),containsString(compressionType));
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWriteWithFlush.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWriteWithFlush.java
new file mode 100644
index 0000000000..ff8841c163
--- /dev/null
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWriteWithFlush.java
@@ -0,0 +1,72 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.servlets.gzip;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.servlets.GzipFilter;
+
+/**
+ * A sample servlet to serve static content, using a order of construction that has caused problems for
+ * {@link GzipFilter} in the past.
+ *
+ * Using a real-world pattern of:
+ *
+ * <pre>
+ * 1) get stream
+ * 2) set content length
+ * 3) set content type
+ * 4) write and flush
+ * </pre>
+ *
+ * @see <a href="Eclipse Bug 354014">http://bugs.eclipse.org/354014</a>
+ */
+@SuppressWarnings("serial")
+public class TestServletStreamLengthTypeWriteWithFlush extends TestDirContentServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ String fileName = request.getServletPath();
+ byte[] dataBytes = loadContentFileBytes(fileName);
+
+ ServletOutputStream out = response.getOutputStream();
+
+ // set content-length of uncompressed content (GzipFilter should handle this)
+ response.setContentLength(dataBytes.length);
+
+ if (fileName.endsWith("txt"))
+ response.setContentType("text/plain");
+ else if (fileName.endsWith("mp3"))
+ response.setContentType("audio/mpeg");
+ response.setHeader("ETag","W/etag-"+fileName);
+
+ for ( int i = 0 ; i < dataBytes.length ; i++)
+ {
+ out.write(dataBytes[i]);
+ // flush using response object (not the stream itself)
+ response.flushBuffer();
+ }
+ }
+} \ No newline at end of file

Back to the top