InvalidOperationException when decompressed data exceeds request body size limit #61723
Closed
1 task done
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Is there an existing issue for this?
Describe the bug
When using the request decompression middleware and the compressed body is below the request body size limit, but the decompressed body exceeds it, the request fails with an
InvalidOperationException
and returns HTTP Status 500 instead of 413 (Content Too Large).Without compression or if the compressed body already exceeds the limit, this internally causes a
BadHttpRequestException
with StatusCode 413 which can properly be handled in a middleware. I would expect the same behaviour here instead of anInvalidOperationException
which cannot be handled properly.The
SizeLimitedStream
that throws the exception was introduced as part of #40279 .Expected Behavior
Same behaviour as without compression, meaning a
BadHttpRequestException
with StatusCode 413.Steps To Reproduce
Then run:
which results in:
Exceptions (if any)
.NET Version
10.0.100-preview.3.25201.16
Anything else?
Reproducible with .NET 9.0.4 and .NET 10 Preview 3 .
The text was updated successfully, but these errors were encountered: