Rémy,

On 3/6/24 09:02, r...@apache.org wrote:
This is an automated email from the ASF dual-hosted git repository.

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

commit 6f85b32c545539f36266ef83218d85c9656ae6a9
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 fb50454dcc..2f66fb46c5 100644
--- a/java/org/apache/catalina/Context.java
+++ b/java/org/apache/catalina/Context.java
@@ -1994,6 +1994,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 eff85041f6..abb7b2fe4d 100644
--- a/java/org/apache/catalina/core/ApplicationDispatcher.java
+++ b/java/org/apache/catalina/core/ApplicationDispatcher.java
@@ -355,7 +355,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 698dadf132..4f13b69a3f 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -798,6 +798,8 @@ public class StandardContext extends ContainerBase 
implements Context, Notificat
private boolean dispatcherWrapsSameObject = Globals.STRICT_SERVLET_COMPLIANCE; + private boolean suspendWrappedResponseAfterForward = false;
+
      private boolean parallelAnnotationScanning = false;
private boolean useBloomFilterForArchives = false;
@@ -881,6 +883,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 eb249a1d16..6ca2063a46 100644
--- a/java/org/apache/catalina/startup/FailedContext.java
+++ b/java/org/apache/catalina/startup/FailedContext.java
@@ -1425,4 +1425,13 @@ public class FailedContext extends LifecycleMBeanBase 
implements Context {
      public void setUseBloomFilterForArchives(boolean 
useBloomFilterForArchives) {
      }
+ @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 1b980556cd..3c7a5cdf0c 100644
--- a/test/org/apache/tomcat/unittest/TesterContext.java
+++ b/test/org/apache/tomcat/unittest/TesterContext.java
@@ -1327,4 +1327,9 @@ public class TesterContext implements Context {
          this.useBloomFilterForArchives = useBloomFilterForArchives;
      }
+ @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 a3738aaac3..5d0b29f31c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -130,7 +130,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>false</code>. (remm)
        </fix>
      </changelog>
    </subsection>
diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml
index c233df716f..5097e59f0f 100644
--- a/webapps/docs/config/context.xml
+++ b/webapps/docs/config/context.xml
@@ -596,6 +596,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>false</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

Your javadoc says that the default is true, but the changelog, Context documentation, and code say it is false.

-chris

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

Reply via email to