Skip to content

Support zstd Content-Encoding#65479

Merged
BrennanConroy merged 8 commits intodotnet:mainfrom
manandre:zstd-encoding
Feb 24, 2026
Merged

Support zstd Content-Encoding#65479
BrennanConroy merged 8 commits intodotnet:mainfrom
manandre:zstd-encoding

Conversation

@manandre
Copy link
Contributor

Support zstd Content-Encoding

This pull request adds support for the Zstandard (zstd) compression algorithm to both the request decompression and response compression middleware. It introduces new provider classes, updates configuration and test files, and ensures Zstandard is used as the default and preferred encoding when available.

Zstandard Compression and Decompression Support

  • Added ZstandardDecompressionProvider and registered it as a default provider in RequestDecompressionOptions, enabling decompression of requests with Content-Encoding: zstd.
  • Added ZstandardCompressionProvider and ZstandardCompressionProviderOptions for response compression, and registered them as default providers.

Configuration and Sample Usage

  • Updated sample Startup.cs to configure Zstandard compression options and add the new provider to the response compression pipeline.

Testing and Verification

  • Enhanced tests to verify Zstandard is a default provider, is case-insensitive, and correctly compresses/decompresses request and response bodies.
  • Updated response compression tests to ensure Zstandard is preferred when available and works with mixed Accept-Encoding headers and wildcards.

Public API Changes

  • Added public API entries for the new Zstandard compression provider and options.

Fixes #50643

… middleware

- Add ZstdCompressionProvider implementing ICompressionProvider
- Add ZstdCompressionProviderOptions with configurable compression level
- Make Zstd the default first compression provider (zstd > brotli > gzip)
- Add comprehensive tests for zstd compression
- Update sample application to demonstrate zstd usage
- Update PublicAPI.Unshipped.txt with new public APIs

Zstandard provides better compression efficiency than gzip with performance
comparable to Brotli, and is now available via System.IO.Compression.ZstandardStream.
…n middleware

- Add ZstdDecompressionProvider implementing IDecompressionProvider
- Add zstd as the default first decompression provider
- Add zstd test cases to existing test suite
- Update RequestDecompressionOptions to include zstd provider

Zstandard decompression is now available alongside gzip, deflate, and brotli.
Copilot AI review requested due to automatic review settings February 19, 2026 23:33
@github-actions github-actions bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Feb 19, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds native Zstandard (zstd) support to ASP.NET Core request decompression and response compression middleware, including new providers/options, updated defaults, and expanded test coverage to validate encoding negotiation and end-to-end compression/decompression behavior.

Changes:

  • Introduces ZstandardCompressionProvider (+ options) for response compression and makes it the first default provider (preferred when available).
  • Introduces ZstandardDecompressionProvider and adds "zstd" to the default request decompression providers.
  • Updates samples, tests, and public API baselines to reflect the new encoding.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Middleware/ResponseCompression/test/ResponseCompressionMiddlewareTest.cs Adds zstd negotiation tests and zstd decompression verification for response bodies.
src/Middleware/ResponseCompression/src/ZstandardCompressionProviderOptions.cs Adds public options type for configuring zstd compression behavior.
src/Middleware/ResponseCompression/src/ZstandardCompressionProvider.cs Adds public response compression provider implementation for Content-Encoding: zstd.
src/Middleware/ResponseCompression/src/ResponseCompressionProvider.cs Changes default provider order to prefer zstd when no providers are configured.
src/Middleware/ResponseCompression/src/PublicAPI.Unshipped.txt Registers new public API surface for zstd provider/options.
src/Middleware/ResponseCompression/sample/Startup.cs Demonstrates configuring and registering the zstd response compression provider.
src/Middleware/RequestDecompression/test/RequestDecompressionOptionsTests.cs Updates default provider assertions to include zstd.
src/Middleware/RequestDecompression/test/RequestDecompressionMiddlewareTests.cs Adds end-to-end request decompression test for Content-Encoding: zstd.
src/Middleware/RequestDecompression/test/DefaultRequestDecompressionProviderTests.cs Adds case-insensitivity coverage for zstd stream selection.
src/Middleware/RequestDecompression/src/ZstandardDecompressionProvider.cs Adds internal provider implementation for zstd request decompression.
src/Middleware/RequestDecompression/src/RequestDecompressionOptions.cs Registers "zstd" in default decompression providers dictionary.

@manandre manandre mentioned this pull request Feb 19, 2026
1 task
Updated comment to clarify the purpose of the factory for resolving default compression providers.
{
private static readonly ZstandardCompressionOptions DefaultZstandardCompressionOptions = new()
{
Quality = 1 // Fastest compression level
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just use the defaults from the underlying zstd library.
https://source.dot.net/#System.IO.Compression.Zstandard/System/IO/Compression/ZstandardCompressionOptions.cs,37

Value 0 indicates the implementation-defined default quality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.
Not aligned with what is done on GZip or Brotli side where the fastest compression level is used by default, but more intuitive from an option point of view.

{
get
{
yield return new EncodingTestData("zstd", expectedBodyLength: 27);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move off of hardcoding the compressed size in tests 😆

Don't need to do it in this PR though since it's not caused by the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good news! These sizes are not used in any test.
I have just removed them.

@BrennanConroy
Copy link
Member

/ba-g unrelated failures

@BrennanConroy BrennanConroy merged commit 2cf27e2 into dotnet:main Feb 24, 2026
23 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview2 milestone Feb 24, 2026
@BrennanConroy
Copy link
Member

Thanks @manandre!

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

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support zstd Content-Encoding

3 participants