Http Request Compression#130082
Draft
iremyux wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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, andZstandardCompressedContentpublicHttpContenttypes. - Factors common header/serialization logic into an internal
CompressedContentCore. - Updates
System.Net.Httpsource/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 | ||
| { |
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.
Adds built-in support for compressing HTTP request content by introducing three new
HttpContenttypes. 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