Skip to content

Http Request Compression#130082

Draft
iremyux wants to merge 4 commits into
dotnet:mainfrom
iremyux:46944-request-compression
Draft

Http Request Compression#130082
iremyux wants to merge 4 commits into
dotnet:mainfrom
iremyux:46944-request-compression

Conversation

@iremyux

@iremyux iremyux commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Adds built-in support for compressing HTTP request content by introducing three new HttpContent types. Every type offers a default constructor plus an options-based overload for tuning compression, with shared serialization logic factored into an internal helper.

Implements #46944

Copilot AI review requested due to automatic review settings July 1, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds new public HttpContent wrappers in System.Net.Http that compress the request body using gzip, Brotli, or Zstandard, with a shared internal helper to handle header copying and serialization.

Changes:

  • Introduces GZipCompressedContent, BrotliCompressedContent, and ZstandardCompressedContent public HttpContent types.
  • Factors common header/serialization logic into an internal CompressedContentCore.
  • Updates System.Net.Http source/ref projects and ref surface to include the new APIs and compression dependencies.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/libraries/System.Net.Http/src/System/Net/Http/BrotliCompressedContent.cs New HttpContent wrapper that applies Brotli request compression.
src/libraries/System.Net.Http/src/System/Net/Http/CompressedContentCore.cs Internal helper for header initialization and (a)synchronous serialization via compression streams.
src/libraries/System.Net.Http/src/System/Net/Http/GZipCompressedContent.cs New HttpContent wrapper that applies gzip request compression.
src/libraries/System.Net.Http/src/System/Net/Http/ZstandardCompressedContent.cs New HttpContent wrapper that applies Zstandard request compression.
src/libraries/System.Net.Http/src/System.Net.Http.csproj Includes the new source files in the build.
src/libraries/System.Net.Http/ref/System.Net.Http.csproj Adds ref-time dependencies on compression ref projects needed by the new public API signatures.
src/libraries/System.Net.Http/ref/System.Net.Http.cs Adds the new public API surface for the three compressed content types.

Comment on lines +54 to +58
Stream compressionStream = _createCompressionStream(stream);
await using (compressionStream.ConfigureAwait(false))
{
await _originalContent.CopyToAsync(compressionStream, cancellationToken).ConfigureAwait(false);
}
Comment on lines +63 to +71
private void ThrowIfContentConsumed()
{
if (_contentConsumed)
{
throw new InvalidOperationException(SR.net_http_content_stream_already_read);
}

_contentConsumed = true;
}
Comment on lines +11 to +15
/// <summary>
/// Shared implementation for the per-algorithm compressed content types. Holds the inner content and
/// drives serialization through a caller-provided factory that wraps the output stream in a compression stream.
/// </summary>
internal sealed class CompressedContentCore
Comment on lines +11 to +15
/// <summary>
/// Provides HTTP content that compresses the inner content using the Brotli content coding.
/// </summary>
public sealed class BrotliCompressedContent : HttpContent
{
Comment on lines +11 to +15
/// <summary>
/// Provides HTTP content that compresses the inner content using the Zstandard content coding.
/// </summary>
public sealed class ZstandardCompressedContent : HttpContent
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants