This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 81ede59fb1 Add new suspendWrappedResponseAfterForward
81ede59fb1 is described below

commit 81ede59fb1da659361b20b373ef7c78f0e23c1ea
Author: remm <r...@apache.org>
AuthorDate: Wed Mar 6 11:44:14 2024 +0100

    Add new suspendWrappedResponseAfterForward
    
    This allow configuring the suspend after forward unwrapping.
---
 java/org/apache/catalina/Context.java                   | 17 +++++++++++++++++
 .../org/apache/catalina/core/ApplicationDispatcher.java |  3 ++-
 java/org/apache/catalina/core/StandardContext.java      | 14 ++++++++++++++
 java/org/apache/catalina/startup/FailedContext.java     |  9 +++++++++
 test/org/apache/tomcat/unittest/TesterContext.java      |  5 +++++
 webapps/docs/changelog.xml                              |  5 ++++-
 webapps/docs/config/context.xml                         |  7 +++++++
 7 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/Context.java 
b/java/org/apache/catalina/Context.java
index f63c7d8e79..b13b6c182f 100644
--- a/java/org/apache/catalina/Context.java
+++ b/java/org/apache/catalina/Context.java
@@ -2003,6 +2003,23 @@ public interface Context extends Container, ContextBind {
     void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject);
 
 
+    /**
+     * If this is <code>true</code>, then following a forward the response will
+     * be unwrapped to suspend the Catalina response instead of simply closing
+     * the top level response. The default value is <code>true</code>.
+     * @return the flag value
+     */
+    boolean getSuspendWrappedResponseAfterForward();
+
+
+    /**
+     * Allows unwrapping the response object to suspend the response following
+     * a forward.
+     * @param suspendWrappedResponseAfterForward the new flag value
+     */
+    void setSuspendWrappedResponseAfterForward(boolean 
suspendWrappedResponseAfterForward);
+
+
     /**
      * Find configuration file with the specified path, first looking into the
      * webapp resources, then delegating to
diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java 
b/java/org/apache/catalina/core/ApplicationDispatcher.java
index d7abfe6ba4..08e43c84a2 100644
--- a/java/org/apache/catalina/core/ApplicationDispatcher.java
+++ b/java/org/apache/catalina/core/ApplicationDispatcher.java
@@ -299,7 +299,8 @@ final class ApplicationDispatcher implements 
AsyncDispatcher, RequestDispatcher
         if (response instanceof ResponseFacade) {
             finished = true;
             ((ResponseFacade) response).finish();
-        } else if (response instanceof ServletResponseWrapper) {
+        } else if (context.getSuspendWrappedResponseAfterForward()
+                && response instanceof ServletResponseWrapper) {
             ServletResponse baseResponse = response;
             do {
                 baseResponse = ((ServletResponseWrapper) 
baseResponse).getResponse();
diff --git a/java/org/apache/catalina/core/StandardContext.java 
b/java/org/apache/catalina/core/StandardContext.java
index f9dd5b060a..fdc59984d4 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -794,6 +794,8 @@ public class StandardContext extends ContainerBase 
implements Context, Notificat
 
     private boolean dispatcherWrapsSameObject = 
Globals.STRICT_SERVLET_COMPLIANCE;
 
+    private boolean suspendWrappedResponseAfterForward = true;
+
     private boolean parallelAnnotationScanning = false;
 
 
@@ -876,6 +878,18 @@ public class StandardContext extends ContainerBase 
implements Context, Notificat
     }
 
 
+    @Override
+    public boolean getSuspendWrappedResponseAfterForward() {
+        return suspendWrappedResponseAfterForward;
+    }
+
+
+    @Override
+    public void setSuspendWrappedResponseAfterForward(boolean 
suspendWrappedResponseAfterForward) {
+        this.suspendWrappedResponseAfterForward = 
suspendWrappedResponseAfterForward;
+    }
+
+
     @Override
     public String getRequestCharacterEncoding() {
         return requestEncoding;
diff --git a/java/org/apache/catalina/startup/FailedContext.java 
b/java/org/apache/catalina/startup/FailedContext.java
index e323e589d2..172d83b319 100644
--- a/java/org/apache/catalina/startup/FailedContext.java
+++ b/java/org/apache/catalina/startup/FailedContext.java
@@ -1436,4 +1436,13 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
     public void setParallelAnnotationScanning(boolean 
parallelAnnotationScanning) {
     }
 
+    @Override
+    public boolean getSuspendWrappedResponseAfterForward() {
+        return false;
+    }
+
+    @Override
+    public void setSuspendWrappedResponseAfterForward(boolean 
suspendWrappedResponseAfterForward) {
+    }
+
 }
\ No newline at end of file
diff --git a/test/org/apache/tomcat/unittest/TesterContext.java 
b/test/org/apache/tomcat/unittest/TesterContext.java
index ea181921c8..926e48a8de 100644
--- a/test/org/apache/tomcat/unittest/TesterContext.java
+++ b/test/org/apache/tomcat/unittest/TesterContext.java
@@ -1331,4 +1331,9 @@ public class TesterContext implements Context {
     @Override
     public void setMetadataComplete(boolean metadataComplete) { /* NO-OP */ }
 
+    @Override
+    public boolean getSuspendWrappedResponseAfterForward() { return true; }
+    @Override
+    public void setSuspendWrappedResponseAfterForward(boolean 
suspendWrappedResponseAfterForward) {}
+
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e3ae2256e6..c46b81488e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -139,7 +139,10 @@
       </fix>
       <fix>
         After forwarding a request, attempt to unwrap the response in order to
-        suspend it, instead of simply closing it if it was wrapped. (remm)
+        suspend it, instead of simply closing it if it was wrapped. Add a new
+        <code>suspendWrappedResponseAfterForward</code> boolean attribute on
+        <code>Context</code> to control the bahavior, defaulting to
+        <code>true</code>. (remm)
       </fix>
     </changelog>
   </subsection>
diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml
index 94f6cba644..c7d6ffc922 100644
--- a/webapps/docs/config/context.xml
+++ b/webapps/docs/config/context.xml
@@ -603,6 +603,13 @@
         attribute is <code>false</code>.</p>
       </attribute>
 
+      <attribute name="suspendWrappedResponseAfterForward" required="false">
+        <p>If the value of this flag is <code>true</code>, Catalina will
+        suspend wrapped responses after a forward, instead of closing them.
+        If not specified, the default value of the flag is
+        <code>true</code>.</p>
+      </attribute>
+
       <attribute name="swallowAbortedUploads" required="false">
         <p>Set to <code>false</code> if Tomcat should <b>not</b> read any
         additional request body data for aborted uploads and instead abort the


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to