Accept-Encoding: zstd support with CMake auto-detection by c41ms0n · Pull Request #508 · litespeedtech/openlitespeed · GitHub
Skip to content

Accept-Encoding: zstd support with CMake auto-detection - #508

Open
c41ms0n wants to merge 1 commit into
litespeedtech:masterfrom
c41ms0n:libzstd
Open

c41ms0n wants to merge 1 commit into
litespeedtech:masterfrom
c41ms0n:libzstd

Conversation

@c41ms0n

@c41ms0n c41ms0n commented Aug 28, 2026 •

Copy link
Copy Markdown

Add zstd as a third response encoding alongside gzip and Brotli, mirrored through the same request-negotiation, config, header, and static-precompression paths. Priority when several encodings are acceptable: zstd > br > gzip.
https://datatracker.ietf.org/doc/html/rfc8478

Build:

  • CMakeModules/FindZstd.cmake: detect libzstd via pkg-config or find_path/find_library, requiring >= 1.4.0 for the streaming API.
  • New WITH_ZSTD cache var (AUTO/ON/OFF, default AUTO); unlike Brotli's manual toggle, this is a real auto-detect.
  • Define USE_ZSTD and link libzstd when found (top-level, src/, test/ CMakeLists.txt).

Core:

  • util/zstdbuf.{h,cpp}: Compressor backed by libzstd's streaming API, mirroring util/brotlibuf.{h,cpp}.
  • http/httpreq.{h,cpp}: parse "zstd" from Accept-Encoding; add ZSTD_ENABLED/REQ_ZSTD_ACCEPT/ZSTD_REQUIRED/UPSTREAM_ZSTD and zstdAcceptable()/andZstd()/orZstd().
  • http/httpserverconfig.{h,cpp}: get/setZstdCompress(), get/setZstdCompressLevel().
  • http/httpvhost.{h,cpp}: VH_ZSTD feature bit, enableZstd(), wired to the per-vhost "enableZstd" directive.
  • http/httprespheaders.{h,cpp}, httpresp.h: ETAG_ZSTD and "content-encoding: zstd" header emission.
  • http/staticfilecachedata.{h,cpp}: SFCD_MODE_ZSTD, ".lsq" precompressed cache files; refactor tryCreateCompressed/ compressFile/readyCompressed/compressHelper from a brotli-only bool onto an algo enum shared by all three codecs.
  • http/staticfilehandler.cpp, sendfileinfo.cpp, subrequest.cpp: include zstd in static-file mode selection and cache lookups.
  • http/httpsession.cpp: factor zstd into compressibility checks and the Content-Encoding strip/passthrough decision. Dynamic (on-the-fly) bodies stay gzip-only via modgzip, same as Brotli.
  • main/httpserver.cpp, plainconf.cpp: new directives enableZstdCompress, zstdCompressLevel, zstdAutoUpdateStatic, zstdStaticCompressLevel.
  • config.h.in: add USE_ZSTD placeholder.

Tests:

  • test/util/zstdbuftest.cpp: streaming round-trip test for ZstdBuf, wired into src/ and test/ CMakeLists.txt.

Add zstd as a third response encoding alongside gzip and Brotli,
mirrored through the same request-negotiation, config, header, and
static-precompression paths. Priority when several encodings are
acceptable: zstd > br > gzip.

Build:
* CMakeModules/FindZstd.cmake: detect libzstd via pkg-config or
  find_path/find_library, requiring >= 1.4.0 for the streaming API.
* New WITH_ZSTD cache var (AUTO/ON/OFF, default AUTO); unlike
  Brotli's manual toggle, this is a real auto-detect.
* Define USE_ZSTD and link libzstd when found (top-level, src/,
  test/ CMakeLists.txt).

Core:
* util/zstdbuf.{h,cpp}: Compressor backed by libzstd's streaming
  API, mirroring util/brotlibuf.{h,cpp}.
* http/httpreq.{h,cpp}: parse "zstd" from Accept-Encoding; add
  ZSTD_ENABLED/REQ_ZSTD_ACCEPT/ZSTD_REQUIRED/UPSTREAM_ZSTD and
  zstdAcceptable()/andZstd()/orZstd().
* http/httpserverconfig.{h,cpp}: get/setZstdCompress(),
  get/setZstdCompressLevel().
* http/httpvhost.{h,cpp}: VH_ZSTD feature bit, enableZstd(), wired
  to the per-vhost "enableZstd" directive.
* http/httprespheaders.{h,cpp}, httpresp.h: ETAG_ZSTD and
  "content-encoding: zstd" header emission.
* http/staticfilecachedata.{h,cpp}: SFCD_MODE_ZSTD, ".lsq"
  precompressed cache files; refactor tryCreateCompressed/
  compressFile/readyCompressed/compressHelper from a brotli-only
  bool onto an algo enum shared by all three codecs.
* http/staticfilehandler.cpp, sendfileinfo.cpp, subrequest.cpp:
  include zstd in static-file mode selection and cache lookups.
* http/httpsession.cpp: factor zstd into compressibility checks
  and the Content-Encoding strip/passthrough decision. Dynamic
  (on-the-fly) bodies stay gzip-only via modgzip, same as Brotli.
* main/httpserver.cpp, plainconf.cpp: new directives
  enableZstdCompress, zstdCompressLevel, zstdAutoUpdateStatic,
  zstdStaticCompressLevel.
* config.h.in: add USE_ZSTD placeholder.

Tests:
* test/util/zstdbuftest.cpp: streaming round-trip test for
  ZstdBuf, wired into src/ and test/ CMakeLists.txt.
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