Search in sources :

Example 1 with ContentMetadata

use of org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata in project jetty.project by eclipse.

the class GzipContentLengthTest method testWithGzip.

private void testWithGzip(Class<? extends TestDirContentServlet> contentServlet) throws Exception {
    GzipTester tester = new GzipTester(testingdir, GzipHandler.GZIP);
    // Add AsyncGzip Configuration
    tester.getGzipHandler().setIncludedMimeTypes("text/plain");
    tester.getGzipHandler().setIncludedPaths("*.txt", "*.mp3");
    // Add content servlet
    tester.setContentServlet(contentServlet);
    try {
        String testFilename = String.format("%s-%s", contentServlet.getSimpleName(), fileName);
        File testFile = tester.prepareServerFile(testFilename, fileSize);
        tester.start();
        HttpTester.Response response = tester.executeRequest("GET", "/context/" + testFile.getName(), 5, TimeUnit.SECONDS);
        if (response.getStatus() != 200)
            System.err.println("DANG!!!! " + response);
        assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
        if (expectCompressed) {
            // Must be gzip compressed
            assertThat("Content-Encoding", response.get("Content-Encoding"), containsString(GzipHandler.GZIP));
        } else {
            assertThat("Content-Encoding", response.get("Content-Encoding"), not(containsString(GzipHandler.GZIP)));
        }
        // Uncompressed content Size
        ContentMetadata content = tester.getResponseMetadata(response);
        assertThat("(Uncompressed) Content Length", content.size, is((long) fileSize));
    } finally {
        tester.stop();
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) ContentMetadata(org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata) HttpTester(org.eclipse.jetty.http.HttpTester)

Example 2 with ContentMetadata

use of org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata in project jetty.project by eclipse.

the class GzipFilterLayeredTest method testGzipDos.

@Test
public void testGzipDos() throws Exception {
    GzipTester tester = new GzipTester(testingdir, GzipHandler.GZIP);
    // Add Gzip Filter first
    FilterHolder gzipHolder = new FilterHolder(gzipFilterClass);
    gzipHolder.setAsyncSupported(true);
    tester.addFilter(gzipHolder, "*.txt", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    tester.addFilter(gzipHolder, "*.mp3", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    gzipHolder.setInitParameter("mimeTypes", "text/plain");
    // Add (DoSFilter-like) manip filter (in chain of Gzip)
    FilterHolder manipHolder = new FilterHolder(AsyncManipFilter.class);
    manipHolder.setAsyncSupported(true);
    tester.addFilter(manipHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    // Add content servlet
    tester.setContentServlet(contentServletClass);
    try {
        String testFilename = String.format("GzipDos-%s-%s", contentServletClass.getSimpleName(), fileName);
        File testFile = tester.prepareServerFile(testFilename, fileSize);
        tester.start();
        HttpTester.Response response = tester.executeRequest("GET", "/context/" + testFile.getName(), 5, TimeUnit.SECONDS);
        assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
        if (expectCompressed) {
            // Must be gzip compressed
            assertThat("Content-Encoding", response.get("Content-Encoding"), containsString(GzipHandler.GZIP));
        }
        // Uncompressed content Size
        ContentMetadata content = tester.getResponseMetadata(response);
        assertThat("(Uncompressed) Content Length", content.size, is((long) fileSize));
    } finally {
        tester.stop();
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) GzipTester(org.eclipse.jetty.server.handler.gzip.GzipTester) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) ContentMetadata(org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 3 with ContentMetadata

use of org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata in project jetty.project by eclipse.

the class GzipFilterLayeredTest method testDosGzip.

@Test
public void testDosGzip() throws Exception {
    GzipTester tester = new GzipTester(testingdir, GzipHandler.GZIP);
    // Add (DoSFilter-like) manip filter
    FilterHolder manipHolder = new FilterHolder(AsyncManipFilter.class);
    manipHolder.setAsyncSupported(true);
    tester.addFilter(manipHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    // Add Gzip Filter first (in chain of DosFilter)
    FilterHolder gzipHolder = new FilterHolder(gzipFilterClass);
    gzipHolder.setAsyncSupported(true);
    tester.addFilter(gzipHolder, "*.txt", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    tester.addFilter(gzipHolder, "*.mp3", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    gzipHolder.setInitParameter("mimeTypes", "text/plain");
    // Add content servlet
    tester.setContentServlet(contentServletClass);
    try {
        String testFilename = String.format("DosGzip-%s-%s", contentServletClass.getSimpleName(), fileName);
        File testFile = tester.prepareServerFile(testFilename, fileSize);
        tester.start();
        HttpTester.Response response = tester.executeRequest("GET", "/context/" + testFile.getName(), 5, TimeUnit.SECONDS);
        assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
        if (expectCompressed) {
            // Must be gzip compressed
            assertThat("Content-Encoding", response.get("Content-Encoding"), containsString(GzipHandler.GZIP));
        } else {
            assertThat("Content-Encoding", response.get("Content-Encoding"), not(containsString(GzipHandler.GZIP)));
        }
        // Uncompressed content Size
        ContentMetadata content = tester.getResponseMetadata(response);
        assertThat("(Uncompressed) Content Length", content.size, is((long) fileSize));
    } finally {
        tester.stop();
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) GzipTester(org.eclipse.jetty.server.handler.gzip.GzipTester) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) ContentMetadata(org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Aggregations

File (java.io.File)3 HttpTester (org.eclipse.jetty.http.HttpTester)3 ContentMetadata (org.eclipse.jetty.server.handler.gzip.GzipTester.ContentMetadata)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GzipTester (org.eclipse.jetty.server.handler.gzip.GzipTester)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 Test (org.junit.Test)2