Add test: MaxResponseContentBufferSize enforced against decompressed content (Brotli)#127864
Add test: MaxResponseContentBufferSize enforced against decompressed content (Brotli)#127864
Conversation
…compressed Brotli data Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/7f712e24-25ff-4525-a48f-e938eb01e97d Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1b67fcea-1c80-4757-9a56-08278aba8835 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
Pull request overview
Adds a new System.Net.Http functional test to ensure HttpClient.MaxResponseContentBufferSize is enforced based on decompressed response size when automatic Brotli decompression is enabled, using the existing loopback server infrastructure in HttpClientHandlerTest.Decompression.cs.
Changes:
- Add a new
Factthat streams highly-compressible Brotli content and asserts the client fails once the decompressed content exceedsMaxResponseContentBufferSize. - Track server-side written (compressed) bytes via a new
ByteCountingStreamwrapper (derived fromDelegatingStream) to assert the server sent less compressed data than the decompressed buffer limit. - Add
System.Threadingimport forCancellationTokenused in the stream wrapper.
|
@copilot The build is failing after the last change to use DelegatingStream: Build FAILED. D:\a_work\1\s\src\libraries\Common\tests\System\Net\Http\HttpClientHandlerTest.Decompression.cs(351,51): error CS0246: The type or namespace name 'DelegatingStream' could not be found (are you missing a using directive or an assembly reference?) [D:\a_work\1\s\src\libraries\System.Net.Http.WinHttpHandler\tests\FunctionalTests\System.Net.Http.WinHttpHandler.Functional.Tests.csproj::TargetFramework=net11.0-windows] 0 Warning(s) 1 Error(s) |
…ByteCountingStream Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/906885b0-b63f-4d08-99fc-6d4102a6439c Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…yteCountingStream to use it Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/c140197c-72f8-42ea-9e8a-c34454989856 Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Done in 0d169e5 — added |
Adds a new System.Net.Http functional test to ensure
HttpClient.MaxResponseContentBufferSizeis enforced based on decompressed response size when automatic Brotli decompression is enabled, using the existing loopback server infrastructure inHttpClientHandlerTest.Decompression.cs.Changes Made
Factthat streams highly-compressible Brotli content and asserts the client fails once the decompressed content exceedsMaxResponseContentBufferSize.ByteCountingStreamwrapper (derived fromDelegatingStream) to assert the server sent less compressed data than the decompressed buffer limit.DelegatingStream.cstoSystem.Net.Http.WinHttpHandler.Functional.Tests.csproj(conditional on.NETCoreAppsince it uses APIs unavailable on net481) to ensureByteCountingStreamcan derive fromDelegatingStreamacross all consuming test projects.Original prompt
Add a test in
dotnet/runtimethat verifiesHttpClientresponse buffering limits are enforced correctly with highly compressed data when automatic decompression is enabled.Context:
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Decompression.cs.MaxResponseContentBufferSizetests live insrc/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs, but they do not cover automatic decompression.MaxResponseContentBufferSizeapplies to decompressed content and did not find one.Requested test behavior:
BrotliStreamusingCompressionLevel.Optimal.Implementation guidance:
Definition of done:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Looking through System.Net.Http tests, find ones where we're checking that MaxResponseContentBufferSize applies to decompressed contents (when using automatic decompression)
Assistant: I found no existing
System.Net.Httptest that explicitly checks thatHttpClient.MaxResponseContentBufferSizeis enforced against the decompressed response size whenAutomaticDecompressionis enabled.Closest related tests are:
DecompressedResponse_MethodSpecified_DecompressedContentReturnedin
src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Decompression.csIt verifies automatic decompression returns the expected decompressed bytes, but does not involve
MaxResponseContentBufferSize.URL:
runtime/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Decompression.cs
Lines 37 to 114 in 5a73be0
MaxResponseContentBufferSize_ThrowsIfTooSmallForContentin
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.csIt verifies buffer-size enforcement for normal content, but uses
CustomResponseHandler/CustomContent, not automatic decompression.URL:
runtime/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs
Lines 128 to 232 in 5a73be0
Relevant snippets: