Skip to content

Commit 2510028

Browse files
author
feiyun0112
committed
Resolve conversation
1 parent 99067e2 commit 2510028

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Middleware/RequestDecompression/src/RequestDecompressionMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private async Task InvokeCore(HttpContext context, Stream decompressionStream)
6262
context.GetEndpoint()?.Metadata?.GetMetadata<IRequestSizeLimitMetadata>()?.MaxRequestBodySize
6363
?? context.Features.Get<IHttpMaxRequestBodySizeFeature>()?.MaxRequestBodySize;
6464

65-
context.Request.Body = new SizeLimitedStream(decompressionStream, sizeLimit, (long totalBytesRead, long sizeLimit) => throw new BadHttpRequestException(
65+
context.Request.Body = new SizeLimitedStream(decompressionStream, sizeLimit, static (long sizeLimit) => throw new BadHttpRequestException(
6666
$"The decompressed request body is larger than the request body size limit {sizeLimit}.",
6767
StatusCodes.Status413PayloadTooLarge));
6868
await _next(context);

src/Shared/SizeLimitedStream.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#nullable enable
5+
46
internal sealed class SizeLimitedStream : Stream
57
{
68
private readonly Stream _innerStream;
79
private readonly long? _sizeLimit;
8-
private readonly Action<long, long>? _handleSizeLimit;
10+
private readonly Action<long>? _handleSizeLimit;
911
private long _totalBytesRead;
1012

11-
public SizeLimitedStream(Stream innerStream, long? sizeLimit, Action<long, long>? handleSizeLimit = null)
13+
public SizeLimitedStream(Stream innerStream, long? sizeLimit, Action<long>? handleSizeLimit = null)
1214
{
1315
ArgumentNullException.ThrowIfNull(innerStream);
1416

@@ -51,7 +53,7 @@ public override int Read(byte[] buffer, int offset, int count)
5153
{
5254
if (_handleSizeLimit != null)
5355
{
54-
_handleSizeLimit(_totalBytesRead, _sizeLimit.Value);
56+
_handleSizeLimit(_sizeLimit.Value);
5557
}
5658
else
5759
{
@@ -91,7 +93,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
9193
{
9294
if (_handleSizeLimit != null)
9395
{
94-
_handleSizeLimit(_totalBytesRead, _sizeLimit.Value);
96+
_handleSizeLimit(_sizeLimit.Value);
9597
}
9698
else
9799
{

0 commit comments

Comments
 (0)