Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes-entries/66149.txt
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 2 additions & 1 deletion modules/filters/mod_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/modules/filters/test_009_mod_deflate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}": """
<Location "/filtertest/">
AddEncoding x-gzip .gz
SetInputFilter DEFLATE
</Location>
""",
})
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"
Loading