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

lukaszlenart pushed a commit to branch feature/WW-5256-freemarker-compress
in repository https://gitbox.apache.org/repos/asf/struts.git

commit cb122c5ab7b1b79fc82e9974886d1dd83161c4e1
Author: Lukasz Lenart <[email protected]>
AuthorDate: Fri Nov 21 10:08:51 2025 +0100

    feat(compress): WW-5256 add global compression configuration
    
    - Add struts.compress.enabled configuration option
    - Compress tag respects global setting unless force=true
    - Add @since 7.2.0 tag to new constant
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude <[email protected]>
---
 core/src/main/java/org/apache/struts2/StrutsConstants.java  |  8 ++++++++
 .../main/java/org/apache/struts2/components/Compress.java   | 13 +++++++++++++
 .../main/resources/org/apache/struts2/default.properties    |  3 +++
 3 files changed, 24 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java 
b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index 457e9642c..4376c45de 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -335,6 +335,14 @@ public final class StrutsConstants {
      */
     public static final String STRUTS_FREEMARKER_WHITESPACE_STRIPPING = 
"struts.freemarker.whitespaceStripping";
 
+    /**
+     * Controls whether the compress tag is enabled globally.
+     * When disabled, the compress tag will not compress output regardless of 
other settings.
+     *
+     * @since 7.2.0
+     */
+    public static final String STRUTS_COMPRESS_ENABLED = 
"struts.compress.enabled";
+
     /**
      * Extension point for the Struts CompoundRootAccessor
      */
diff --git a/core/src/main/java/org/apache/struts2/components/Compress.java 
b/core/src/main/java/org/apache/struts2/components/Compress.java
index aa6765c07..8a60737e6 100644
--- a/core/src/main/java/org/apache/struts2/components/Compress.java
+++ b/core/src/main/java/org/apache/struts2/components/Compress.java
@@ -18,8 +18,11 @@
  */
 package org.apache.struts2.components;
 
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.inject.Inject;
 import org.apache.struts2.util.ValueStack;
 import org.apache.struts2.views.annotations.StrutsTag;
 import org.apache.struts2.views.annotations.StrutsTagAttribute;
@@ -73,15 +76,25 @@ public class Compress extends Component {
     private static final Logger LOG = LogManager.getLogger(Compress.class);
 
     private String force;
+    private boolean compressionEnabled = true;
 
     public Compress(ValueStack stack) {
         super(stack);
     }
 
+    @Inject(value = StrutsConstants.STRUTS_COMPRESS_ENABLED, required = false)
+    public void setCompressionEnabled(String compressionEnabled) {
+        this.compressionEnabled = BooleanUtils.toBoolean(compressionEnabled);
+    }
+
     @Override
     public boolean end(Writer writer, String body) {
         Object forceValue = findValue(force, Boolean.class);
         boolean forced = forceValue != null && 
Boolean.parseBoolean(forceValue.toString());
+        if (!compressionEnabled && !forced) {
+            LOG.debug("Compression disabled globally, skipping: {}", body);
+            return super.end(writer, body, true);
+        }
         if (devMode && !forced) {
             LOG.debug("Avoids compressing output: {} in DevMode", body);
             return super.end(writer, body, true);
diff --git a/core/src/main/resources/org/apache/struts2/default.properties 
b/core/src/main/resources/org/apache/struts2/default.properties
index 60c77514f..f8903ead2 100644
--- a/core/src/main/resources/org/apache/struts2/default.properties
+++ b/core/src/main/resources/org/apache/struts2/default.properties
@@ -211,6 +211,9 @@ struts.freemarker.mru.max.strong.size=0
 ### Automatically disabled when devMode is enabled.
 struts.freemarker.whitespaceStripping=true
 
+### Controls whether the compress tag is enabled globally.
+struts.compress.enabled=true
+
 ### configure the XSLTResult class to use stylesheet caching.
 ### Set to true for developers and false for production.
 struts.xslt.nocache=false

Reply via email to