Add HTTP gzip/zstd compression and WebSocket permessage-deflate support#819
Open
ProjectSky wants to merge 3 commits intoithewei:masterfrom
Open
Add HTTP gzip/zstd compression and WebSocket permessage-deflate support#819ProjectSky wants to merge 3 commits intoithewei:masterfrom
ProjectSky wants to merge 3 commits intoithewei:masterfrom
Conversation
ProjectSky
commented
Mar 18, 2026
- Add configurable HTTP gzip/zstd compression support
- Add WebSocket permessage-deflate negotiation & message handling
- Add WITH_ZLIB/WITH_ZSTD build options and update build/docs/CI
- Add compression-related unit tests
There was a problem hiding this comment.
Pull request overview
This PR adds first-class HTTP response/request compression (gzip/zstd) and WebSocket permessage-deflate support, including negotiation, framing (RSV1), and extensive unit test coverage. It also introduces new build toggles (WITH_ZLIB/WITH_ZSTD) and wires them into the project’s build + CI tooling.
Changes:
- Add HTTP compression utilities (Accept-Encoding selection, request/response compression, streaming decompression) and integrate into HTTP server/client paths.
- Add WebSocket permessage-deflate negotiation plus RSV1-aware frame building, compression on send, and decompression in the WebSocket parser.
- Add new HTTP/WebSocket compression unit tests and update CMake/Make/Bazel/CI/build docs to support zlib/zstd options.
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
unittest/websocket_compression_test.cpp |
Adds negotiation + parser safety tests and an end-to-end compressed WebSocket echo test. |
unittest/http_compression_test.cpp |
Adds comprehensive HTTP compression/decompression behavior tests (client/server, headers, edge cases). |
unittest/CMakeLists.txt |
Builds the new compression test binaries under HTTP-enabled configurations. |
scripts/unittest.sh |
Runs new compression tests when the binaries are present. |
http/wsdef.h / http/wsdef.c |
Adds ws_build_frame_ex to support RSV1 when building frames. |
http/websocket_parser.h / http/websocket_parser.c |
Tracks RSV bits during parse and supports RSV1 emission during build. |
http/server/WebSocketServer.h |
Adds server-side WebSocket compression options to WebSocketService. |
http/server/HttpService.h |
Adds server-wide HttpCompressionOptions defaults on HttpService. |
http/server/HttpResponseWriter.h / .cpp |
Threads request/service context into writer and applies compression before sending headers/body. |
http/server/HttpHandler.h / .cpp |
Implements request decompression, response compression, static-file ETag variance by encoding, and WS extension negotiation. |
http/http_compress.h / http/http_compress.cpp |
Introduces the shared compression implementation (HTTP + WS helpers, streaming decoder, deflater/inflater). |
http/client/WebSocketClient.h / .cpp |
Adds permessage-deflate offer/confirm logic and config surface to the client. |
http/client/HttpClient.h / .cpp |
Adds client compression configuration, request auto-compress, response auto-decode via adapter; adjusts redirect flow. |
http/client/AsyncHttpClient.h / .cpp |
Adds response decoder adapter support and request auto-compress for async client. |
http/WebSocketParser.h / .cpp |
Adds permessage-deflate decompression support and stricter frame validation (RSV/opcodes/control frames). |
http/WebSocketChannel.h / .cpp |
Adds permessage-deflate compression on send and RSV1 marking on first frame. |
http/HttpMessage.h / .cpp |
Adds compression options to messages plus Content-Encoding helpers and Accept-Encoding builder. |
http/HttpCompression.h |
Defines public compression option structs and content-encoding enums. |
configure / config.ini |
Adds configure/config toggles for WITH_ZLIB/WITH_ZSTD. |
cmake/vars.cmake / CMakeLists.txt |
Adds headers and build options for zlib/zstd. |
Makefile.vars / Makefile.in / Makefile |
Adds headers and link flags, and builds compression tests in make unittest. |
BUILD.md |
Documents how to build with zlib/zstd enabled. |
BUILD.bazel |
Adds zlib/zstd defines/linkopts and new compression cc_test targets. |
.github/workflows/CI.yml |
Installs zlib/zstd deps and enables them in CI configure invocation. |
base/herr.h |
Adds new error codes for unsupported encoding/compress/decompress failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ion check, and make compression tests work without zstd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.