This commit is contained in:
parent
5e8cc2243e
commit
c8b3373bbc
|
@ -73,7 +73,7 @@
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- Reuse Forks causes test failures -->
|
<!-- Reuse Forks causes test failures -->
|
||||||
<reuseForks>false</reuseForks>
|
<reuseForks>true</reuseForks>
|
||||||
<argLine>@{argLine} ${jetty.surefire.argLine}
|
<argLine>@{argLine} ${jetty.surefire.argLine}
|
||||||
--add-modules org.eclipse.jetty.util.ajax
|
--add-modules org.eclipse.jetty.util.ajax
|
||||||
--add-reads org.eclipse.jetty.ee9.servlet=org.eclipse.jetty.logging</argLine>
|
--add-reads org.eclipse.jetty.ee9.servlet=org.eclipse.jetty.logging</argLine>
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -2569,44 +2570,52 @@ public class DefaultServletTest
|
||||||
@Test
|
@Test
|
||||||
public void testGetPrecompressedSuffixMapping() throws Exception
|
public void testGetPrecompressedSuffixMapping() throws Exception
|
||||||
{
|
{
|
||||||
Path docRoot = workDir.getEmptyPathDir().resolve("docroot");
|
final AtomicReference<ResourceFactory> oldFileResourceFactory = new AtomicReference<>();
|
||||||
FS.ensureDirExists(docRoot);
|
try
|
||||||
|
|
||||||
startServer((context) ->
|
|
||||||
{
|
{
|
||||||
ResourceFactory.registerResourceFactory("file", new URLResourceFactory());
|
Path docRoot = workDir.getEmptyPathDir().resolve("docroot");
|
||||||
Resource resource = ResourceFactory.of(context).newResource(docRoot);
|
FS.ensureDirExists(docRoot);
|
||||||
assertThat("Expecting URLResource", resource.getClass().getName(), endsWith("URLResource"));
|
|
||||||
context.setBaseResource(resource);
|
|
||||||
|
|
||||||
ServletHolder defholder = context.addServlet(DefaultServlet.class, "*.js");
|
startServer((context) ->
|
||||||
defholder.setInitParameter("cacheControl", "no-store");
|
{
|
||||||
defholder.setInitParameter("dirAllowed", "false");
|
oldFileResourceFactory.set(ResourceFactory.unregisterResourceFactory("file"));
|
||||||
defholder.setInitParameter("gzip", "false");
|
ResourceFactory.registerResourceFactory("file", new URLResourceFactory());
|
||||||
defholder.setInitParameter("precompressed", "gzip=.gz");
|
Resource resource = ResourceFactory.of(context).newResource(docRoot);
|
||||||
});
|
assertThat("Expecting URLResource", resource.getClass().getName(), endsWith("URLResource"));
|
||||||
|
context.setBaseResource(resource);
|
||||||
|
|
||||||
|
ServletHolder defholder = context.addServlet(DefaultServlet.class, "*.js");
|
||||||
|
defholder.setInitParameter("cacheControl", "no-store");
|
||||||
|
defholder.setInitParameter("dirAllowed", "false");
|
||||||
|
defholder.setInitParameter("gzip", "false");
|
||||||
|
defholder.setInitParameter("precompressed", "gzip=.gz");
|
||||||
|
});
|
||||||
|
|
||||||
FS.ensureDirExists(docRoot.resolve("scripts"));
|
FS.ensureDirExists(docRoot.resolve("scripts"));
|
||||||
|
|
||||||
String scriptText = "This is a script";
|
String scriptText = "This is a script";
|
||||||
Files.writeString(docRoot.resolve("scripts/script.js"), scriptText, UTF_8);
|
Files.writeString(docRoot.resolve("scripts/script.js"), scriptText, UTF_8);
|
||||||
|
|
||||||
byte[] compressedBytes = compressGzip(scriptText);
|
byte[] compressedBytes = compressGzip(scriptText);
|
||||||
Files.write(docRoot.resolve("scripts/script.js.gz"), compressedBytes);
|
Files.write(docRoot.resolve("scripts/script.js.gz"), compressedBytes);
|
||||||
|
|
||||||
String rawResponse = connector.getResponse("""
|
String rawResponse = connector.getResponse("""
|
||||||
GET /context/scripts/script.js HTTP/1.1
|
GET /context/scripts/script.js HTTP/1.1
|
||||||
Host: test
|
Host: test
|
||||||
Accept-Encoding: gzip
|
Accept-Encoding: gzip
|
||||||
Connection: close
|
Connection: close
|
||||||
|
|
||||||
""");
|
""");
|
||||||
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
|
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
|
||||||
assertThat(response.getStatus(), is(HttpStatus.OK_200));
|
assertThat(response.getStatus(), is(HttpStatus.OK_200));
|
||||||
assertThat("Suffix url-pattern mapping not used", response.get(HttpHeader.CACHE_CONTROL), is("no-store"));
|
assertThat("Suffix url-pattern mapping not used", response.get(HttpHeader.CACHE_CONTROL), is("no-store"));
|
||||||
String responseDecompressed = decompressGzip(response.getContentBytes());
|
String responseDecompressed = decompressGzip(response.getContentBytes());
|
||||||
assertThat(responseDecompressed, is("This is a script"));
|
assertThat(responseDecompressed, is("This is a script"));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ResourceFactory.registerResourceFactory("file", oldFileResourceFactory.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue