Skip to content

Commit

Permalink
Issue #6544 - Updates based on review
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Jul 30, 2021
1 parent 1bdb69d commit 72fc018
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
4 changes: 2 additions & 2 deletions demos/demo-simple-webapp/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -7,8 +7,8 @@
<display-name>Simple Web Application</display-name>

<mime-mapping>
<extension>webp</extension>
<mime-type>image/webp</mime-type>
<extension>icon</extension>
<mime-type>image/vnd.microsoft.icon</mime-type>
</mime-mapping>

</web-app>
Binary file not shown.
Expand Up @@ -25,7 +25,6 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -44,8 +43,6 @@ public void testGzipDefault() throws Exception
.build();

int httpPort = distribution.freePort();
int httpsPort = distribution.freePort();
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));

String[] argsConfig = {
"--add-modules=gzip",
Expand All @@ -59,8 +56,7 @@ public void testGzipDefault() throws Exception

String[] argsStart = {
"jetty.http.port=" + httpPort,
"jetty.httpConfig.port=" + httpsPort,
"jetty.ssl.port=" + httpsPort
"jetty.httpConfig.port=" + httpPort
};

File war = distribution.resolveArtifact("org.eclipse.jetty.demos:demo-simple-webapp:war:" + jettyVersion);
Expand All @@ -79,7 +75,7 @@ public void testGzipDefault() throws Exception
}

@Test
public void testGzipExcludeMimeType() throws Exception
public void testGzipDefaultExcludedMimeType() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
Expand All @@ -90,8 +86,6 @@ public void testGzipExcludeMimeType() throws Exception
.build();

int httpPort = distribution.freePort();
int httpsPort = distribution.freePort();
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));

String[] argsConfig = {
"--add-modules=gzip",
Expand All @@ -105,9 +99,7 @@ public void testGzipExcludeMimeType() throws Exception

String[] argsStart = {
"jetty.http.port=" + httpPort,
"jetty.httpConfig.port=" + httpsPort,
"jetty.ssl.port=" + httpsPort,
"jetty.gzip.excludedMimeTypeList=image/webp"
"jetty.httpConfig.port=" + httpPort
};

File war = distribution.resolveArtifact("org.eclipse.jetty.demos:demo-simple-webapp:war:" + jettyVersion);
Expand All @@ -120,11 +112,57 @@ public void testGzipExcludeMimeType() throws Exception
startHttpClient();
ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.webp");
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/webp"));
assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
}
}
}

@Test
public void testGzipAddWebappSpecificExcludeMimeType() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();

int httpPort = distribution.freePort();

String[] argsConfig = {
"--add-modules=gzip",
"--add-modules=deploy,webapp,http"
};

try (JettyHomeTester.Run runConfig = distribution.start(argsConfig))
{
assertTrue(runConfig.awaitFor(5, TimeUnit.SECONDS));
assertEquals(0, runConfig.getExitValue());

String[] argsStart = {
"jetty.http.port=" + httpPort,
"jetty.httpConfig.port=" + httpPort,
"jetty.gzip.excludedMimeTypeList=image/vnd.microsoft.icon"
};

File war = distribution.resolveArtifact("org.eclipse.jetty.demos:demo-simple-webapp:war:" + jettyVersion);
distribution.installWarFile(war, "demo");

try (JettyHomeTester.Run runStart = distribution.start(argsStart))
{
assertTrue(runStart.awaitConsoleLogsFor("Started Server@", 20, TimeUnit.SECONDS));

startHttpClient();
ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.icon");
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/vnd.microsoft.icon"));
}
}
}

private static class ResponseDetails implements Supplier<String>
{
private final ContentResponse response;
Expand Down

0 comments on commit 72fc018

Please sign in to comment.