This is an automated email from the ASF dual-hosted git repository. markt 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 f486275 Fix BZ 64593. Delay 404 when Context is null. f486275 is described below commit f48627583be79d3cd2260ba832e004834e413537 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Jul 13 16:46:23 2020 +0100 Fix BZ 64593. Delay 404 when Context is null. This gives the rewrite valve an opportunity to rewrite the request. --- java/org/apache/catalina/connector/CoyoteAdapter.java | 8 ++++---- java/org/apache/catalina/core/StandardEngineValve.java | 6 +++++- java/org/apache/catalina/core/StandardHostValve.java | 4 ++++ webapps/docs/changelog.xml | 5 +++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 8587bfd..ddbf14f 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -700,11 +700,11 @@ public class CoyoteAdapter implements Adapter { // because no ROOT context has been deployed or the URI was invalid // so no context could be mapped. if (request.getContext() == null) { - // Don't overwrite an existing error - if (!response.isError()) { - response.sendError(404); - } // Allow processing to continue. + // If present, the rewrite Valve may rewrite this to a valid + // request. + // The StandardEngineValve will handle the case of a missing + // Host and the StandardHostValve the case of a missing Context. // If present, the error reporting valve will provide a response // body. return true; diff --git a/java/org/apache/catalina/core/StandardEngineValve.java b/java/org/apache/catalina/core/StandardEngineValve.java index 96ef64e..688d522 100644 --- a/java/org/apache/catalina/core/StandardEngineValve.java +++ b/java/org/apache/catalina/core/StandardEngineValve.java @@ -63,7 +63,11 @@ final class StandardEngineValve extends ValveBase { Host host = request.getHost(); if (host == null) { // HTTP 0.9 or HTTP 1.0 request without a host when no default host - // is defined. This is handled by the CoyoteAdapter. + // is defined. + // Don't overwrite an existing error + if (!response.isError()) { + response.sendError(404); + } return; } if (request.isAsyncSupported()) { diff --git a/java/org/apache/catalina/core/StandardHostValve.java b/java/org/apache/catalina/core/StandardHostValve.java index c713652..26e9f2a 100644 --- a/java/org/apache/catalina/core/StandardHostValve.java +++ b/java/org/apache/catalina/core/StandardHostValve.java @@ -110,6 +110,10 @@ final class StandardHostValve extends ValveBase { // Select the Context to be used for this Request Context context = request.getContext(); if (context == null) { + // Don't overwrite an existing error + if (!response.isError()) { + response.sendError(404); + } return; } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index f124d55..e40b98e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -52,6 +52,11 @@ prevent a potential exception when running under a security manager. Patch provided by Johnathan Gilday. (markt) </fix> + <fix> + <bug>64593</bug>: If a request is not matched to a Context, delay + issuing the 404 response to give the rewrite valve, if configured, an + opportunity to rewrite the request. (remm/markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org