diff --git a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/ResponseHeadersTest.java b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/ResponseHeadersTest.java index f24a77fa5e5b..9a800e117358 100644 --- a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/ResponseHeadersTest.java +++ b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/ResponseHeadersTest.java @@ -19,7 +19,11 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.ArrayList; import java.util.EnumSet; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Stream; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterChain; @@ -31,6 +35,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpTester; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.UriCompliance; @@ -39,12 +44,15 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.toolchain.test.MavenPaths; import org.eclipse.jetty.util.StringUtil; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertTrue; public class ResponseHeadersTest @@ -150,11 +158,24 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t } } - private static Server server; - private static LocalConnector connector; + private Server server; + private LocalConnector connector; - @BeforeAll - public static void startServer() throws Exception + public void startServer() throws Exception + { + startServer((context) -> + { + context.addServlet(new ServletHolder(new DefaultServlet()), "/default/*"); + context.addFilter(new FilterHolder(new WrappingFilter()), "/default/*", EnumSet.allOf(DispatcherType.class)); + context.addServlet(new ServletHolder(new SimulateUpgradeServlet()), "/ws/*"); + context.addServlet(new ServletHolder(new MultilineResponseValueServlet()), "/multiline/*"); + context.addServlet(CharsetResetToJsonMimeTypeServlet.class, "/charset/json-reset/*"); + context.addServlet(CharsetChangeToJsonMimeTypeServlet.class, "/charset/json-change/*"); + context.addServlet(CharsetChangeToJsonMimeTypeSetCharsetToNullServlet.class, "/charset/json-change-null/*"); + }); + } + + public void startServer(Consumer configureServletContext) throws Exception { Path staticContentPath = MavenPaths.findTestResourceDir("contextResources"); server = new Server(); @@ -165,21 +186,15 @@ public static void startServer() throws Exception context.setContextPath("/"); context.setBaseResourceAsPath(staticContentPath); context.setInitParameter("org.eclipse.jetty.servlet.Default.pathInfoOnly", "TRUE"); - server.setHandler(context); - context.addServlet(new ServletHolder(new DefaultServlet()), "/default/*"); - context.addFilter(new FilterHolder(new WrappingFilter()), "/default/*", EnumSet.allOf(DispatcherType.class)); - context.addServlet(new ServletHolder(new SimulateUpgradeServlet()), "/ws/*"); - context.addServlet(new ServletHolder(new MultilineResponseValueServlet()), "/multiline/*"); - context.addServlet(CharsetResetToJsonMimeTypeServlet.class, "/charset/json-reset/*"); - context.addServlet(CharsetChangeToJsonMimeTypeServlet.class, "/charset/json-change/*"); - context.addServlet(CharsetChangeToJsonMimeTypeSetCharsetToNullServlet.class, "/charset/json-change-null/*"); + configureServletContext.accept(context); + server.setHandler(context); server.start(); } - @AfterAll - public static void stopServer() + @AfterEach + public void stopServer() { try { @@ -208,6 +223,7 @@ public void testWrappedResponseWithStaticContent() throws Exception @Test public void testResponseWebSocketHeaderFormat() throws Exception { + startServer(); HttpTester.Request request = new HttpTester.Request(); request.setMethod("GET"); request.setURI("/ws/"); @@ -226,6 +242,7 @@ public void testResponseWebSocketHeaderFormat() throws Exception @Test public void testMultilineResponseHeaderValue() throws Exception { + startServer(); connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setUriCompliance(UriCompliance.UNSAFE); String actualPathInfo = "%0a%20Content-Type%3a%20image/png%0a%20Content-Length%3a%208%0A%20%0A%20yuck