From 901c2eb23c10dd54e70e48b7ea9a8f69657d0e89 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Wed, 25 Nov 2026 10:50:39 +0100 Subject: [PATCH 1/3] docs(rum): explain that compressed HTML is not injected Document the INFLATE;DEFLATE workaround for proxied gzip HTML and test it. Refs INPLAT-1455. --- doc/configuration.md | 27 +++++++++++++++++++ .../integration-test/test_rum_streaming.py | 19 ++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/configuration.md b/doc/configuration.md index e73fde7..6d37c2f 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -165,6 +165,33 @@ RUM SDK injection applies only to responses whose `Content-Type` media type is ` The check is case-insensitive and accepts parameters, such as `text/html; charset=utf-8`. Responses with a missing or different media type are left unchanged. +### Compressed HTML + +The module does not inject into a response that already has a `Content-Encoding` header, because +it cannot read compressed HTML. The response is sent unchanged, and the `injection.skipped` +telemetry metric gets `reason:compressed_html`. This often happens with `mod_proxy`: Apache +forwards the client `Accept-Encoding: gzip` header, and the backend returns gzip HTML. + +To inject and still send compressed HTML to the client, let `mod_deflate` decompress the HTML +before the module and compress it again after: + +``` +LoadModule deflate_module modules/mod_deflate.so +LoadModule filter_module modules/mod_filter.so + + + ProxyPass "http://backend:8080/" + AddOutputFilterByType INFLATE;DEFLATE text/html + +``` + +`INFLATE` runs before the module and `DEFLATE` runs after it. Other content types are not changed. +Clients that do not accept gzip get uncompressed HTML. + +> [!NOTE] +> `RequestHeader unset Accept-Encoding` also makes the backend send uncompressed HTML. But +> `mod_deflate` reads the same header, so the response to the client is not compressed either. + ## `DatadogRumSettings` section - **Description**: Container for Datadog RUM settings - **Syntax:**: diff --git a/test/rum/integration-test/test_rum_streaming.py b/test/rum/integration-test/test_rum_streaming.py index 7507e35..4cae016 100644 --- a/test/rum/integration-test/test_rum_streaming.py +++ b/test/rum/integration-test/test_rum_streaming.py @@ -85,7 +85,13 @@ def streaming_proxy(server: Server, log_dir: str, module_path: str, mode: str) - with ExitStack() as cleanup: docroot = cleanup.enter_context(tempfile.TemporaryDirectory(prefix="rum-streaming-")) proxy = cleanup.enter_context(upstream_proxy(StreamingUpstream)) - if mode != "no-deflate": + if mode == "inflate-deflate": + proxy += ( + "\nLoadModule deflate_module modules/mod_deflate.so" + "\nLoadModule filter_module modules/mod_filter.so" + "\nAddOutputFilterByType INFLATE;DEFLATE text/html\n" + ) + elif mode != "no-deflate": proxy += "\nLoadModule deflate_module modules/mod_deflate.so\nSetOutputFilter DEFLATE\n" cleanup.callback(server.stop, conf_path) configuration = { @@ -153,3 +159,14 @@ def test_rum_streaming_keeps_precompressed_body(streaming_proxy: Server) -> None assert response.headers.get("Content-Encoding") == "gzip" assert response.headers.get("x-datadog-rum-injected") != "1" assert response.raw.read() == PRECOMPRESSED_BODY + + +# The workaround documented for compressed HTML. +@pytest.mark.requires_rum +@pytest.mark.parametrize("mode", ["inflate-deflate"], indirect=True) +def test_rum_streaming_injects_after_inflate(streaming_proxy: Server) -> None: + with open_stream(streaming_proxy, "/upstream/precompressed", "gzip") as response: + assert response.status_code == 200 + assert response.headers.get("Content-Encoding") == "gzip" + assert response.headers.get("x-datadog-rum-injected") == "1" + assert b"DD_RUM" in response.content From 3053faa23afbcb57c7ec9711796da67763a298d2 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Wed, 25 Nov 2026 10:53:35 +0100 Subject: [PATCH 2/3] docs(rum): note gzip only and CPU cost of INFLATE --- doc/configuration.md | 5 ++++- test/rum/integration-test/test_rum_streaming.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/configuration.md b/doc/configuration.md index 6d37c2f..49ba8f8 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -186,7 +186,10 @@ LoadModule filter_module modules/mod_filter.so ``` `INFLATE` runs before the module and `DEFLATE` runs after it. Other content types are not changed. -Clients that do not accept gzip get uncompressed HTML. +Clients that do not accept gzip get uncompressed HTML. Each HTML response is decompressed and +compressed again, which uses CPU. + +`INFLATE` decodes only gzip. HTML compressed another way (for example `br`) is still not injected. > [!NOTE] > `RequestHeader unset Accept-Encoding` also makes the backend send uncompressed HTML. But diff --git a/test/rum/integration-test/test_rum_streaming.py b/test/rum/integration-test/test_rum_streaming.py index 4cae016..1c2367e 100644 --- a/test/rum/integration-test/test_rum_streaming.py +++ b/test/rum/integration-test/test_rum_streaming.py @@ -161,7 +161,6 @@ def test_rum_streaming_keeps_precompressed_body(streaming_proxy: Server) -> None assert response.raw.read() == PRECOMPRESSED_BODY -# The workaround documented for compressed HTML. @pytest.mark.requires_rum @pytest.mark.parametrize("mode", ["inflate-deflate"], indirect=True) def test_rum_streaming_injects_after_inflate(streaming_proxy: Server) -> None: From 213c3dd8d2cae5a64a102b6f3ccf191c85491a10 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Wed, 25 Nov 2026 11:03:30 +0100 Subject: [PATCH 3/3] docs(rum): drop telemetry detail from user doc --- doc/configuration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/configuration.md b/doc/configuration.md index 49ba8f8..895831c 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -168,9 +168,9 @@ Responses with a missing or different media type are left unchanged. ### Compressed HTML The module does not inject into a response that already has a `Content-Encoding` header, because -it cannot read compressed HTML. The response is sent unchanged, and the `injection.skipped` -telemetry metric gets `reason:compressed_html`. This often happens with `mod_proxy`: Apache -forwards the client `Accept-Encoding: gzip` header, and the backend returns gzip HTML. +it cannot read compressed HTML. The response is sent unchanged. This often happens with +`mod_proxy`: Apache forwards the client `Accept-Encoding: gzip` header, and the backend returns +gzip HTML. To inject and still send compressed HTML to the client, let `mod_deflate` decompress the HTML before the module and compress it again after: