Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-05-30 21:07:40 -0400
committerGreg Wilkins2013-05-30 21:07:40 -0400
commit3849c893e17834c1bdb5fbf73ae911dd43ff1c6f (patch)
tree4466b59fba57252738c95be9633f479c58555dc6 /jetty-servlets/src
parentc869aad1450fa2f597f2ab81b123006e3cccad6c (diff)
parent3094f93ed99c21ef4e6883282978496c3f0f8d01 (diff)
downloadorg.eclipse.jetty.project-3849c893e17834c1bdb5fbf73ae911dd43ff1c6f.tar.gz
org.eclipse.jetty.project-3849c893e17834c1bdb5fbf73ae911dd43ff1c6f.tar.xz
org.eclipse.jetty.project-3849c893e17834c1bdb5fbf73ae911dd43ff1c6f.zip
Merge remote-tracking branch 'origin/jetty-7' into jetty-8
Diffstat (limited to 'jetty-servlets/src')
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java53
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java58
2 files changed, 106 insertions, 5 deletions
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 f6db638904..0298b6e8e6 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
@@ -145,7 +145,7 @@ public class GzipFilterDefaultTest
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)));
+ // 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)));
}
@@ -272,6 +272,57 @@ public class GzipFilterDefaultTest
tester.stop();
}
}
+
+
+ @Test
+ public void testGzipedIfModified() throws Exception
+ {
+ GzipTester tester = new GzipTester(testingdir, compressionType);
+
+ // Test content that is smaller than the buffer.
+ int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
+ tester.prepareServerFile("file.txt",filesize);
+
+ FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+ holder.setInitParameter("mimeTypes","text/plain");
+
+ try
+ {
+ tester.start();
+ HttpTester http = tester.assertIsResponseGzipCompressed("GET","file.txt",System.currentTimeMillis()-4000);
+ Assert.assertEquals("Accept-Encoding",http.getHeader("Vary"));
+ }
+ finally
+ {
+ tester.stop();
+ }
+ }
+
+
+ @Test
+ public void testNotGzipedIfNotModified() throws Exception
+ {
+ GzipTester tester = new GzipTester(testingdir, compressionType);
+
+ // Test content that is smaller than the buffer.
+ int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
+ tester.prepareServerFile("file.txt",filesize);
+
+ FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+ holder.setInitParameter("mimeTypes","text/plain");
+ holder.setInitParameter("etags","true");
+
+ try
+ {
+ tester.start();
+ HttpTester http = tester.assertIsResponseNotModified("GET","file.txt",System.currentTimeMillis()+4000);
+ }
+ finally
+ {
+ tester.stop();
+ }
+ }
+
@Test
public void testIsNotGzipCompressedWithQ() throws Exception
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 5b92a940d3..5129d0d80e 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
@@ -47,6 +47,8 @@ import java.util.zip.InflaterInputStream;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.http.HttpFields;
+import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
@@ -56,6 +58,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.eclipse.jetty.util.DateCache;
import org.hamcrest.Matchers;
import org.junit.Assert;
@@ -80,10 +83,20 @@ public class GzipTester
{
return assertIsResponseGzipCompressed(method,filename,filename);
}
+
+ public HttpTester assertIsResponseGzipCompressed(String method,String filename,long ifmodifiedsince) throws Exception
+ {
+ return assertIsResponseGzipCompressed(method,filename,filename,ifmodifiedsince);
+ }
public HttpTester assertIsResponseGzipCompressed(String method,String requestedFilename, String serverFilename) throws Exception
{
- System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
+ return assertIsResponseGzipCompressed(method,requestedFilename,serverFilename,-1);
+ }
+
+ public HttpTester assertIsResponseGzipCompressed(String method,String requestedFilename, String serverFilename, long ifmodifiedsince) throws Exception
+ {
+ //System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
@@ -91,6 +104,8 @@ public class GzipTester
request.setVersion("HTTP/1.0");
request.setHeader("Host","tester");
request.setHeader("Accept-Encoding",compressionType);
+ if (ifmodifiedsince>0)
+ request.setHeader(HttpHeaders.IF_MODIFIED_SINCE,HttpFields.formatDate(ifmodifiedsince));
if (this.userAgent != null)
request.setHeader("User-Agent", this.userAgent);
request.setURI("/context/" + requestedFilename);
@@ -100,7 +115,7 @@ public class GzipTester
// Collect the response(s)
ByteArrayBuffer respBuff = servletTester.getResponses(reqsBuff);
response.parse(respBuff.asArray());
-
+
// Assert the response headers
Assert.assertThat("Response.method",response.getMethod(),nullValue());
// Assert.assertThat("Response.status",response.getStatus(),is(HttpServletResponse.SC_OK));
@@ -147,6 +162,41 @@ public class GzipTester
return response;
}
+
+
+ public HttpTester assertIsResponseNotModified(String method,String requestedFilename, long ifmodifiedsince) throws Exception
+ {
+ return assertIsResponseNotModified(method,requestedFilename,requestedFilename,ifmodifiedsince);
+ }
+
+ public HttpTester assertIsResponseNotModified(String method,String requestedFilename, String serverFilename, long ifmodifiedsince) throws Exception
+ {
+ //System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
+ HttpTester request = new HttpTester();
+ HttpTester response = new HttpTester();
+
+ request.setMethod(method);
+ request.setVersion("HTTP/1.0");
+ request.setHeader("Host","tester");
+ request.setHeader("Accept-Encoding",compressionType);
+ if (ifmodifiedsince>0)
+ request.setHeader(HttpHeaders.IF_MODIFIED_SINCE,HttpFields.formatDate(ifmodifiedsince));
+ if (this.userAgent != null)
+ request.setHeader("User-Agent", this.userAgent);
+ request.setURI("/context/" + requestedFilename);
+
+ // Issue the request
+ ByteArrayBuffer reqsBuff = new ByteArrayBuffer(request.generate().getBytes());
+ // Collect the response(s)
+ ByteArrayBuffer respBuff = servletTester.getResponses(reqsBuff);
+ response.parse(respBuff.asArray());
+
+ Assert.assertThat(response.getStatus(),Matchers.equalTo(304));
+ Assert.assertThat(response.getHeader("ETag"),Matchers.startsWith("W/"));
+
+ return response;
+ }
+
/**
* Makes sure that the response contains an unfiltered file contents.
@@ -165,7 +215,7 @@ public class GzipTester
*/
public void assertIsResponseNotGzipFiltered(String requestedFilename, String testResourceSha1Sum, String expectedContentType) throws Exception
{
- System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
+ // System.err.printf("[GzipTester] requesting /context/%s%n",requestedFilename);
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
@@ -328,7 +378,7 @@ public class GzipTester
private HttpTester executeRequest(String method,String uri) throws IOException, Exception
{
- System.err.printf("[GzipTester] requesting %s%n",uri);
+ //System.err.printf("[GzipTester] requesting %s%n",uri);
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();

Back to the top