This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 32f3a25140 Add test for status change and forward 32f3a25140 is described below commit 32f3a25140ca12c162738a1699a22a05bfe16e4f Author: remm <r...@apache.org> AuthorDate: Fri Oct 11 09:21:42 2024 +0200 Add test for status change and forward Based on the idea of PR#763 but simplified. The original bug was about not being able to set new status code if a status >= 400 was set. --- .../apache/catalina/connector/TestResponse.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/org/apache/catalina/connector/TestResponse.java b/test/org/apache/catalina/connector/TestResponse.java index 79c26c8ceb..5b3d46a80d 100644 --- a/test/org/apache/catalina/connector/TestResponse.java +++ b/test/org/apache/catalina/connector/TestResponse.java @@ -40,6 +40,7 @@ import org.apache.tomcat.unittest.TesterContext; import org.apache.tomcat.unittest.TesterRequest; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.collections.CaseInsensitiveKeyMap; +import org.apache.tomcat.util.descriptor.web.ErrorPage; /** * Test case for {@link Request}. @@ -959,6 +960,26 @@ public class TestResponse extends TomcatBaseTest { Assert.assertEquals(ISO_8859_1, response.getCharacterEncoding()); } + @Test + public void testStatusChange() throws Exception { + // Setup Tomcat instance + Tomcat tomcat = getTomcatInstance(); + + // No file system docBase required + Context ctx = getProgrammaticRootContext(); + + Tomcat.addServlet(ctx, "servlet", new ErrorPageServlet()); + ctx.addServletMappingDecoded("/error", "servlet"); + ErrorPage servletErrorPage = new ErrorPage(); + servletErrorPage.setErrorCode(404); + servletErrorPage.setLocation("/error"); + ctx.addErrorPage(servletErrorPage); + + tomcat.start(); + + int rc = getUrl("http://localhost:" + getPort() + "/missing", new ByteChunk(), null); + Assert.assertEquals(202, rc); + } private Response setupResponse() { Connector connector = new Connector(); @@ -1001,4 +1022,17 @@ public class TestResponse extends TomcatBaseTest { } } + + private static final class ErrorPageServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + if (resp.getStatus() == 404) { + resp.setStatus(202); + } else { + resp.setStatus(500); + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org