SLING-11514 : Provide dispatcher option to ignore header changes on include
diff --git a/src/main/java/org/apache/sling/api/request/RequestDispatcherOptions.java b/src/main/java/org/apache/sling/api/request/RequestDispatcherOptions.java
index 3230bff..86ed85f 100644
--- a/src/main/java/org/apache/sling/api/request/RequestDispatcherOptions.java
+++ b/src/main/java/org/apache/sling/api/request/RequestDispatcherOptions.java
@@ -73,6 +73,13 @@
     public static final String OPT_REPLACE_EXTENSION = "replaceExtension";
 
     /**
+     * When dispatching with the include method, any headers set by the included
+     * resource are ignored. This defaults to "false".
+     * @since 2.7.0
+     */
+    public static final String OPT_PROTECT_HEADERS_ON_INCLUDE = "protectHeadersOnInclude";
+
+    /**
      * Creates an instance with no options set.
      */
     public RequestDispatcherOptions() {
@@ -220,4 +227,24 @@
     public String getReplaceExtension() {
         return get(OPT_REPLACE_EXTENSION);
     }
+
+   /**
+     * Sets the {@link #OPT_PROTECT_HEADERS_ON_INCLUDE} option to the given
+     * value.
+     * @param flag The value to set
+     * @since 2.7.0
+     */
+    public void setProtectHeadersOnInclude(final boolean flag) {
+        put(OPT_PROTECT_HEADERS_ON_INCLUDE, String.valueOf(flag));
+    }
+
+    /**
+     * Returns the {@link #OPT_PROTECT_HEADERS_ON_INCLUDE} option or <code>false</code> if
+     * not set.
+     * @return Are headers protected on include?
+     * @since 2.7.0
+     */
+    public boolean isProtectHeadersOnInclude() {
+        return Boolean.valueOf(this.getOrDefault(OPT_PROTECT_HEADERS_ON_INCLUDE, "false"));
+    }
 }
diff --git a/src/main/java/org/apache/sling/api/request/package-info.java b/src/main/java/org/apache/sling/api/request/package-info.java
index 3dc8622..f265b91 100644
--- a/src/main/java/org/apache/sling/api/request/package-info.java
+++ b/src/main/java/org/apache/sling/api/request/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("2.6.0")
+@Version("2.7.0")
 package org.apache.sling.api.request;
 
 import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/api/request/RequestDispatcherOptionsTest.java b/src/test/java/org/apache/sling/api/request/RequestDispatcherOptionsTest.java
index a1ad768..05f81c5 100644
--- a/src/test/java/org/apache/sling/api/request/RequestDispatcherOptionsTest.java
+++ b/src/test/java/org/apache/sling/api/request/RequestDispatcherOptionsTest.java
@@ -19,6 +19,7 @@
 package org.apache.sling.api.request;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -100,5 +101,19 @@
     @Test public void testReplaceExtensionConstructor() {
         final RequestDispatcherOptions result = new RequestDispatcherOptions("replaceExtension=foo");
         assertEquals("foo", result.getReplaceExtension());
-    } 
+    }
+
+    @Test public void testProtectHeadersOnInclude() {
+        final RequestDispatcherOptions options = new RequestDispatcherOptions();
+        assertNull(options.get(RequestDispatcherOptions.OPT_PROTECT_HEADERS_ON_INCLUDE));
+        assertFalse(options.isProtectHeadersOnInclude());
+
+        options.setProtectHeadersOnInclude(true);
+        assertEquals("true", options.get(RequestDispatcherOptions.OPT_PROTECT_HEADERS_ON_INCLUDE));
+        assertTrue(options.isProtectHeadersOnInclude());
+
+        options.setProtectHeadersOnInclude(false);
+        assertEquals("false", options.get(RequestDispatcherOptions.OPT_PROTECT_HEADERS_ON_INCLUDE));
+        assertFalse(options.isProtectHeadersOnInclude());
+    }
 }