Skip to content
Merged
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
30 changes: 30 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,36 @@ 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. 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

<Location "/app/">
ProxyPass "http://backend:8080/"
AddOutputFilterByType INFLATE;DEFLATE text/html
</Location>
```

`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. 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
> `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:**:
Expand Down
18 changes: 17 additions & 1 deletion test/rum/integration-test/test_rum_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -153,3 +159,13 @@ 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


@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
Loading