Skip to content

Add optional gzip request compression - #189

Open
turtledreams wants to merge 1 commit into
stagingfrom
request-compression
Open

turtledreams wants to merge 1 commit into
stagingfrom
request-compression

Conversation

@turtledreams

Copy link
Copy Markdown
Contributor

Adds optional compression of request bodies.

  • New init option enable_request_compression, off by default.
  • With it on, the SDK behavior settings request carries gzip=1. A server that reads compressed bodies answers with "gzip": true next to c. The SDK keeps that answer in memory for the server URL it came from and never stores it.
  • Then a POST body between 1 KB and 1 MB (never multipart) is compressed with zlib.gzip on the thread pool and sent to the endpoint with ?content_encoding=gzip. A body over 1 MB goes plain, because the server refuses a larger compressed body. The Content-Type stays application/x-www-form-urlencoded and no Content-Encoding header is set. A body goes compressed only when it gets smaller. Requests sent as GET (under 2,000 characters without force_post) are unchanged.
  • A compressed request that is answered but not accepted stops compression, and the request is retried plain. Compression starts again when a later SDK behavior settings answer says "gzip": true, or when the SDK starts again. Network errors and timeouts do not stop it.
  • The queue, storage, checksum and logs keep the plain body.
  • A server without this support never answers "gzip": true, so it keeps getting plain requests.
Success criterion How it was checked
Option off: no gzip=1, plain bodies Mocha
Server says gzip: a body of 1 KB or more goes to ?content_encoding=gzip as gzip, decodes to the plain body and carries the plain body's checksum Mocha
Body under 1 KB stays plain Mocha
Server without the gzip key gets plain bodies Mocha
Body over 1 MB stays plain and compression stays on Mocha
Refused compressed request: the retry and later requests go plain Mocha
After a refusal, a new settings answer with gzip turns compression on again Mocha
A compressed remote config download answered with JSON keeps compression on; one answered with a page or nothing stops it Mocha
A compressed request that got no answer keeps compression on Mocha
After change_server_url, plain until the new server says gzip Mocha
Only "gzip": true counts Mocha
A server with the support stores compressed batches correctly Manual: a 30-event batch went as 569 bytes of gzip (8,411 plain), every event was stored

Tests: test/tests_request_compression.js (13 tests). The full suite (263 tests) and lint pass.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

CI report

Check Result Summary
CodeQL ✅ passed
Node.js CI ✅ passed
Public API changelog ✅ passed
Public API changes ✅ passed Public API: No public API change
Public API changes: Public API, No public API change

No public API change.

For 3079629, updated 2026-11-18 04:14 UTC. Each check's run page has its full log.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant