Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-05-27 06:47:27 +0000
committerGreg Wilkins2013-05-27 06:47:27 +0000
commit6ef865b153d4ce3f3731ba349df11b9c8f811d66 (patch)
treeb10f558811484221715cf40b08eb77af15be9507 /jetty-servlets
parent725dc261c8844a12cd7bf3a4703274a0f638e6c0 (diff)
parent16994cbd6c60fad9a6c63a896794af5103770cdd (diff)
downloadorg.eclipse.jetty.project-6ef865b153d4ce3f3731ba349df11b9c8f811d66.tar.gz
org.eclipse.jetty.project-6ef865b153d4ce3f3731ba349df11b9c8f811d66.tar.xz
org.eclipse.jetty.project-6ef865b153d4ce3f3731ba349df11b9c8f811d66.zip
Merge remote-tracking branch 'origin/jetty-7' into jetty-8
Conflicts: VERSION.txt example-jetty-embedded/pom.xml jetty-aggregate/jetty-all-server/pom.xml jetty-aggregate/jetty-all/pom.xml jetty-aggregate/jetty-client/pom.xml jetty-aggregate/jetty-plus/pom.xml jetty-aggregate/jetty-server/pom.xml jetty-aggregate/jetty-servlet/pom.xml jetty-aggregate/jetty-webapp/pom.xml jetty-aggregate/jetty-websocket/pom.xml jetty-aggregate/pom.xml jetty-ajp/pom.xml jetty-annotations/pom.xml jetty-client/pom.xml jetty-continuation/pom.xml jetty-deploy/pom.xml jetty-distribution/pom.xml jetty-http-spi/pom.xml jetty-http/pom.xml jetty-io/pom.xml jetty-jaspi/pom.xml jetty-jmx/pom.xml jetty-jndi/pom.xml jetty-jsp/pom.xml jetty-monitor/pom.xml jetty-nested/pom.xml jetty-nosql/pom.xml jetty-osgi/jetty-osgi-boot-jsp/pom.xml jetty-osgi/jetty-osgi-boot-warurl/pom.xml jetty-osgi/jetty-osgi-boot/pom.xml jetty-osgi/jetty-osgi-httpservice/pom.xml jetty-osgi/pom.xml jetty-osgi/test-jetty-osgi-context/pom.xml jetty-osgi/test-jetty-osgi-webapp/pom.xml jetty-osgi/test-jetty-osgi/pom.xml jetty-overlay-deployer/pom.xml jetty-plus/pom.xml jetty-policy/pom.xml jetty-rewrite/pom.xml jetty-security/pom.xml jetty-server/pom.xml jetty-servlet/pom.xml jetty-servlets/pom.xml jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java jetty-spdy/pom.xml jetty-spdy/spdy-core/pom.xml jetty-spdy/spdy-jetty-http-webapp/pom.xml jetty-spdy/spdy-jetty-http/pom.xml jetty-spdy/spdy-jetty/pom.xml jetty-start/pom.xml jetty-util/pom.xml jetty-webapp/pom.xml jetty-websocket/pom.xml jetty-xml/pom.xml pom.xml test-continuation/pom.xml test-jetty-nested/pom.xml test-jetty-servlet/pom.xml test-jetty-webapp/pom.xml tests/pom.xml tests/test-integration/pom.xml tests/test-loginservice/pom.xml tests/test-sessions/pom.xml tests/test-sessions/test-hash-sessions/pom.xml tests/test-sessions/test-jdbc-sessions/pom.xml tests/test-sessions/test-mongodb-sessions/pom.xml tests/test-sessions/test-sessions-common/pom.xml tests/test-webapps/pom.xml tests/test-webapps/test-webapp-rfc2616/pom.xml
Diffstat (limited to 'jetty-servlets')
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java15
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java57
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java22
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java1
9 files changed, 91 insertions, 9 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 0b1d21891b..885a01d0c4 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
@@ -33,7 +33,10 @@ import org.eclipse.jetty.servlets.gzip.TestServletStreamLengthTypeWrite;
import org.eclipse.jetty.servlets.gzip.TestServletStreamTypeLengthWrite;
import org.eclipse.jetty.servlets.gzip.TestServletTypeLengthStreamWrite;
import org.eclipse.jetty.servlets.gzip.TestServletTypeStreamLengthWrite;
+import org.eclipse.jetty.testing.HttpTester;
import org.eclipse.jetty.toolchain.test.TestingDir;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -131,7 +134,8 @@ public class GzipFilterContentLengthTest
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET",testfile.getName(),filesize,HttpStatus.OK_200);
+ HttpTester response = tester.assertIsResponseNotGzipCompressed("GET",testfile.getName(),filesize,HttpStatus.OK_200);
+ Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("w/etag-"));
}
finally
{
@@ -143,6 +147,15 @@ public class GzipFilterContentLengthTest
* Tests gzip compression of a small size file
*/
@Test
+ public void testEmpty() throws Exception
+ {
+ assertIsNotGzipCompressed("empty.txt",0);
+ }
+
+ /**
+ * Tests gzip compression of a small size file
+ */
+ @Test
public void testIsGzipCompressedSmall() throws Exception
{
assertIsGzipCompressed("file-small.txt",SMALL);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
index c420c4ce1e..f6db638904 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java
@@ -79,6 +79,7 @@ public class GzipFilterDefaultTest
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setStatus(_status);
+ resp.setHeader("ETag","W/\"204\"");
}
}
@@ -141,11 +142,40 @@ public class GzipFilterDefaultTest
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,ServletException
{
+ String uri=req.getRequestURI();
+ if (uri.endsWith(".deferred"))
+ {
+ System.err.println("type for "+uri.substring(0,uri.length()-9)+" is "+getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
+ resp.setContentType(getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
+ }
+
doGet(req,resp);
}
}
+
+ @Test
+ public void testIsGzipCompressedEmpty() throws Exception
+ {
+ GzipTester tester = new GzipTester(testingdir, compressionType);
+
+ // Test content that is smaller than the buffer.
+ tester.prepareServerFile("empty.txt",0);
+
+ FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+ holder.setInitParameter("mimeTypes","text/plain");
+
+ try
+ {
+ tester.start();
+ HttpTester http = tester.assertIsResponseNotGzipCompressed("GET","empty.txt",0,200);
+ }
+ finally
+ {
+ tester.stop();
+ }
+ }
@Test
public void testIsGzipCompressedTiny() throws Exception
@@ -242,7 +272,7 @@ public class GzipFilterDefaultTest
tester.stop();
}
}
-
+
@Test
public void testIsNotGzipCompressedWithQ() throws Exception
{
@@ -267,7 +297,7 @@ public class GzipFilterDefaultTest
}
@Test
- public void testIsNotGzipCompressed() throws Exception
+ public void testIsNotGzipCompressedByContentType() throws Exception
{
GzipTester tester = new GzipTester(testingdir, compressionType);
@@ -290,6 +320,29 @@ public class GzipFilterDefaultTest
}
@Test
+ public void testIsNotGzipCompressedByDeferredContentType() throws Exception
+ {
+ GzipTester tester = new GzipTester(testingdir, compressionType);
+
+ int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
+ tester.prepareServerFile("file.mp3.deferred",filesize);
+
+ FilterHolder holder = tester.setContentServlet(GetServlet.class);
+ holder.setInitParameter("mimeTypes","text/plain");
+
+ try
+ {
+ tester.start();
+ HttpTester http = tester.assertIsResponseNotGzipCompressed("GET","file.mp3.deferred", filesize, HttpStatus.OK_200);
+ Assert.assertNull(http.getHeader("Vary"));
+ }
+ finally
+ {
+ tester.stop();
+ }
+ }
+
+ @Test
public void testIsNotGzipCompressedHttpStatus() throws Exception
{
GzipTester tester = new GzipTester(testingdir, compressionType);
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 c4ee7331d8..7a09b5795f 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
@@ -56,6 +56,7 @@ 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.hamcrest.Matchers;
import org.junit.Assert;
public class GzipTester
@@ -110,6 +111,8 @@ public class GzipTester
else
Assert.assertThat("Response.header[Content-Encoding]", response.getHeader("Content-Encoding"),containsString(compressionType.substring(0,qindex)));
+ Assert.assertThat(response.getHeader("ETag"),Matchers.startsWith("W/"));
+
// Assert that the decompressed contents are what we expect.
File serverFile = testdir.getFile(serverFilename);
String expected = IO.readToString(serverFile);
@@ -191,6 +194,8 @@ public class GzipTester
Assert.assertThat(prefix + ".header[Content-Type] (should have a Content-Type associated with it)",response.getHeader("Content-Type"),notNullValue());
Assert.assertThat(prefix + ".header[Content-Type]",response.getHeader("Content-Type"),is(expectedContentType));
+ Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("w/etag-"));
+
ByteArrayInputStream bais = null;
DigestOutputStream digester = null;
try
@@ -315,6 +320,10 @@ public class GzipTester
int serverLength = Integer.parseInt(response.getHeader("Content-Length"));
Assert.assertThat("Response.header[Content-Length]",serverLength,is(expectedFilesize));
}
+
+ if (status>=200 && status<300)
+ Assert.assertThat(response.getHeader("ETAG"),Matchers.startsWith("W/"));
+
}
private HttpTester executeRequest(String method,String uri) throws IOException, Exception
@@ -347,11 +356,11 @@ public class GzipTester
ByteArrayOutputStream out = null;
try
{
- in = new ByteArrayInputStream(response.getContentBytes());
- out = new ByteArrayOutputStream();
- IO.copy(in,out);
-
- actual = out.toString(encoding);
+ byte[] content=response.getContentBytes();
+ if (content!=null)
+ actual=new String(response.getContentBytes(),encoding);
+ else
+ actual="";
}
finally
{
@@ -434,7 +443,7 @@ public class GzipTester
finally
{
IO.close(in);
- IO.close(fos);
+ IO.close(fos);
}
}
@@ -466,6 +475,7 @@ public class GzipTester
servletTester.setResourceBase(testdir.getDir().getCanonicalPath());
ServletHolder servletHolder = servletTester.addServlet(servletClass,"/");
servletHolder.setInitParameter("baseDir",testdir.getDir().getAbsolutePath());
+ servletHolder.setInitParameter("etags","true");
FilterHolder holder = servletTester.addFilter(gzipFilterClass,"/*",EnumSet.allOf(DispatcherType.class));
holder.setInitParameter("vary","Accept-Encoding");
return holder;
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
index 72fa2620ae..c318facd9a 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthStreamTypeWrite.java
@@ -59,6 +59,7 @@ public class TestServletLengthStreamTypeWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
out.write(dataBytes);
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
index 84a6ce3a6a..227fc9f5f4 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletLengthTypeStreamWrite.java
@@ -57,6 +57,7 @@ public class TestServletLengthTypeStreamWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
ServletOutputStream out = response.getOutputStream();
out.write(dataBytes);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
index a5046881e6..b54fcdc77d 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamLengthTypeWrite.java
@@ -59,6 +59,7 @@ public class TestServletStreamLengthTypeWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
out.write(dataBytes);
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
index 7b412d0cf3..54ca2789b7 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletStreamTypeLengthWrite.java
@@ -57,6 +57,7 @@ public class TestServletStreamTypeLengthWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
response.setContentLength(dataBytes.length);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
index 1ae34f0ed5..2ae83eee2c 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeLengthStreamWrite.java
@@ -55,6 +55,7 @@ public class TestServletTypeLengthStreamWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
response.setContentLength(dataBytes.length);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
index 0d1def6f9b..67c1e72d8d 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/TestServletTypeStreamLengthWrite.java
@@ -55,6 +55,7 @@ public class TestServletTypeStreamLengthWrite extends TestDirContentServlet
response.setContentType("text/plain");
else if (fileName.endsWith("mp3"))
response.setContentType("audio/mpeg");
+ response.setHeader("ETag","w/etag-"+fileName);
ServletOutputStream out = response.getOutputStream();

Back to the top