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"