From 0d53dafc751f69f44632e54aea4f7c739707ced9 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Tue, 17 Nov 2026 19:53:21 +0100 Subject: [PATCH] mod_deflate: Keep the response Content-Encoding with the input filter check_gzip() syncs r->content_encoding with the Content-Encoding of the headers it was given. That is meant for the response headers of the output filters, but the input filter passes r->headers_in, so the response's Content-Encoding (e.g. from AddEncoding) was replaced by the request's, which is usually none. Only sync it for the response headers. PR 66149. --- changes-entries/66149.txt | 3 ++ modules/filters/mod_deflate.c | 3 +- test/modules/filters/test_009_mod_deflate.py | 29 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 changes-entries/66149.txt diff --git a/changes-entries/66149.txt b/changes-entries/66149.txt new file mode 100644 index 00000000000..1aed9ba268d --- /dev/null +++ b/changes-entries/66149.txt @@ -0,0 +1,3 @@ + *) mod_deflate: Fix a missing Content-Encoding in the response, e.g. set + with AddEncoding, when the DEFLATE input filter is configured. + PR 66149. [Arturo Bernal] diff --git a/modules/filters/mod_deflate.c b/modules/filters/mod_deflate.c index 95d4de41651..b35110374b5 100644 --- a/modules/filters/mod_deflate.c +++ b/modules/filters/mod_deflate.c @@ -178,8 +178,9 @@ static int check_gzip(request_rec *r, apr_table_t *hdrs1, apr_table_t *hdrs2) * before sync it with the new value in the hdrs table as * r->content_encoding takes precedence later on in the http_header_filter * and hence would destroy what we have just set in the hdrs table. + * The request headers are not the response's: leave it alone for them. */ - if (hdrs && r->content_encoding) { + if (hdrs && hdrs != r->headers_in && r->content_encoding) { r->content_encoding = apr_table_get(hdrs, "Content-Encoding"); } return found; diff --git a/test/modules/filters/test_009_mod_deflate.py b/test/modules/filters/test_009_mod_deflate.py index a4a75122548..3991d4d4924 100644 --- a/test/modules/filters/test_009_mod_deflate.py +++ b/test/modules/filters/test_009_mod_deflate.py @@ -72,3 +72,32 @@ def test_filters_009_02(self, env): body = r.response["body"].decode() assert "Good morning, fellow!" in body, \ f"expected original content (decompressed by curl), got: {body!r}" + + @pytest.mark.parametrize("body", [False, True], ids=["no-body", "gzip-body"]) + def test_filters_009_03(self, env, body): + """An input DEFLATE filter inflates the request body only; the + Content-Encoding of the response must be left alone (PR 66149).""" + conf = HttpdConf(env, extras={ + f"test1.{env.http_tld}": """ + + AddEncoding x-gzip .gz + SetInputFilter DEFLATE + + """, + }) + conf.add_vhost_test1() + conf.install() + assert env.apache_restart() == 0 + url = env.mkurl("http", "test1", "/filtertest/hello.txt.gz") + options = [] + if body: + # A gzipped body is inflated while it is read and discarded. + body_path = os.path.join(env.gen_dir, "body_009_03.gz") + with open(body_path, "wb") as f: + f.write(gzip.compress(b"request body")) + options = ["-X", "GET", "-H", "Content-Encoding: gzip", + "--data-binary", f"@{body_path}"] + r = env.curl_get(url, options=options) + assert r.response, "no response" + assert r.response["status"] == 200 + assert r.response["header"].get("content-encoding") == "x-gzip"