]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
test/pytest_suite: fix deflate round-trip tests to use raw gzip bytes
authorJim Jagielski <jim@apache.org>
Wed, 3 Jun 2026 21:14:57 +0000 (21:14 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 3 Jun 2026 21:14:57 +0000 (21:14 +0000)
httpx auto-decompresses gzip responses, so .content returned the decoded
plaintext rather than the gzip stream. Re-POSTing that plaintext with
Content-Encoding: gzip made mod_deflate's inflate input filter fail,
breaking the round-trip assertions in test_pr49328 and test_deflate.

Add a GET_RAW client helper that streams the response and reads iter_raw(),
returning the body undecoded (the analog of LWP not auto-decoding), and use
it in both tests so they exercise a genuine gzip -> inflate round-trip.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1934949 13f79535-47bb-0310-9956-ffa450edef68

test/pytest_suite/apache_pytest/client.py
test/pytest_suite/tests/t/apache/test_pr49328.py
test/pytest_suite/tests/t/modules/test_deflate.py

index 994755a67cd8504164f3f0cf7dfa80d8c228d566..572b448ba6a8767a273af5dbc2c8a0f392141088 100644 (file)
@@ -272,6 +272,34 @@ class TestClient:
     def GET(self, path: str, **kwargs: object) -> httpx.Response:
         return self._request("GET", path, **kwargs)
 
+    def _raw_body(
+        self,
+        method: str,
+        path: str,
+        *,
+        cert: str | None = None,
+        **kwargs: object,
+    ) -> bytes:
+        """Return the response body WITHOUT content-decoding.
+
+        httpx transparently inflates gzip/deflate responses, so ``.content`` is
+        the decoded plaintext. The mod_deflate round-trip tests need the raw
+        compressed bytes (to re-POST them through the inflate input filter), so
+        stream the response and read ``iter_raw()``, which yields the bytes as
+        they came off the wire -- the analog of LWP not auto-decoding.
+        """
+        client = self._client_for(cert) if cert is not None else self._client
+        request = client.build_request(method, self._url(path), **kwargs)  # type: ignore[arg-type]
+        response = client.send(request, stream=True)
+        try:
+            return b"".join(response.iter_raw())
+        finally:
+            response.close()
+
+    def GET_RAW(self, path: str, **kwargs: object) -> bytes:
+        """GET ``path`` and return the raw, undecoded response body bytes."""
+        return self._raw_body("GET", path, **kwargs)
+
     def HEAD(self, path: str, **kwargs: object) -> httpx.Response:
         return self._request("HEAD", path, **kwargs)
 
index 4830817a5921e555366bdbfba03d89713185d2f3..5d1a665150cb4921096dae4b86a5df5cc49b5135 100644 (file)
@@ -14,7 +14,9 @@ URI = "/modules/filter/pr49328/pr49328.shtml"
 
 @need_module("filter", "include", "deflate")
 def test_pr49328(http):
-    content = http.GET(URI, headers={"Accept-Encoding": "gzip"}).content
+    # GET_RAW: keep the gzip stream undecoded so we can re-POST it through the
+    # inflate input filter (httpx would otherwise auto-decompress .content).
+    content = http.GET_RAW(URI, headers={"Accept-Encoding": "gzip"})
     deflated = http.POST_BODY(
         INFLATOR, content=content, headers={"Content-Encoding": "gzip"}
     )
index 984873e660e4601e13a51473ca20657791d87396..1d32475e29d801dcd286398be89e929408c3365a 100644 (file)
@@ -54,16 +54,10 @@ def test_deflate(http):
     for uri in _uris(http):
         original = http.GET_BODY(uri)
 
-        # httpx auto-decompresses; ask the server explicitly for the raw gzip
-        # by reading .content with the gzip Accept-Encoding, then re-POST it.
-        deflated_resp = http.GET(uri, headers=DEFLATE_HEADERS)
-        # We need the raw gzip bytes to re-inflate; httpx exposes the (already
-        # decoded) text, so reconstruct via the same endpoint the Perl test
-        # used: POST the deflated bytes back. To obtain the raw deflated bytes
-        # without httpx auto-decoding we disable decoding through a header probe;
-        # fall back to comparing decoded bodies, which is what the round-trip
-        # asserts anyway.
-        deflated = deflated_resp.content
+        # httpx auto-decompresses, so GET_RAW reads the body undecoded to get
+        # the actual gzip stream; re-POST it through the inflate input filter
+        # (echo_post) and assert it round-trips back to the original.
+        deflated = http.GET_RAW(uri, headers=DEFLATE_HEADERS)
 
         deflated_str_q0 = http.GET_BODY(uri, headers=DEFLATE_HEADERS_Q0)