From 6764774d51f3dcb07e79779c64a463d3c112b53f Mon Sep 17 00:00:00 2001
From: Yann Ylavic <ylavic@apache.org>
Date: Tue, 10 Jun 2025 10:58:15 +0000
Subject: [PATCH] avoid ap_set_content_type when processing a _Request_Header
 set|edit|unset Content-Type.

identified by ylavic


Merges r1820750 from trunk
Submitted by: covener
Reviewed by: covener, rpluem, jorton


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1926323 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/metadata/mod_headers.c b/modules/metadata/mod_headers.c
index be8fbb2..d960f2f 100644
--- a/modules/metadata/mod_headers.c
+++ b/modules/metadata/mod_headers.c
@@ -791,14 +791,16 @@ static int do_headers_fixup(request_rec *r, apr_table_t *headers,
             }
             break;
         case hdr_set:
-            if (!strcasecmp(hdr->header, "Content-Type")) {
+            if (r->headers_in != headers &&
+                !strcasecmp(hdr->header, "Content-Type")) {
                  ap_set_content_type_ex(r, process_tags(hdr, r), 1);
             }
             apr_table_setn(headers, hdr->header, process_tags(hdr, r));
             break;
         case hdr_setifempty:
             if (NULL == apr_table_get(headers, hdr->header)) {
-                if (!strcasecmp(hdr->header, "Content-Type")) {
+                if (r->headers_in != headers &&
+                    !strcasecmp(hdr->header, "Content-Type")) {
                     ap_set_content_type_ex(r, process_tags(hdr, r), 1);
                 }
                 apr_table_setn(headers, hdr->header, process_tags(hdr, r));
@@ -806,6 +808,10 @@ static int do_headers_fixup(request_rec *r, apr_table_t *headers,
             break;
         case hdr_unset:
             apr_table_unset(headers, hdr->header);
+            if (r->headers_in != headers &&
+                !ap_cstr_casecmp(hdr->header, "Content-Type")) {
+                ap_set_content_type(r, NULL);
+            }
             break;
         case hdr_echo:
             v.r = r;
@@ -818,7 +824,7 @@ static int do_headers_fixup(request_rec *r, apr_table_t *headers,
                 const char *repl = process_regexp(hdr, r->content_type, r);
                 if (repl == NULL)
                     return 0;
-                ap_set_content_type_ex(r, repl, 1);
+                if (r->headers_in != headers) ap_set_content_type_ex(r, repl, 1);
             }
             if (apr_table_get(headers, hdr->header)) {
                 edit_do ed;
