Skip to content

Commit 826393b

Browse files
committed
fix: 修正中间件未遵循context.DoNotWrapResponse()的问题
1 parent b36bb6b commit 826393b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Cuture.AspNetCore.ResponseAutoWrapper/Cuture.AspNetCore.ResponseAutoWrapper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<IsPackable>true</IsPackable>
1717
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1818

19-
<Version>1.2.4</Version>
19+
<Version>1.2.5</Version>
2020
<Description>Response and exception automatic wrapper for `asp.net core` to provide a consistent response content format for `Action`. 用于`asp.net core`的响应和异常自动包装器,使`Action`提供一致的响应内容格式。</Description>
2121

2222
<PackageIdPrefix>Cuture.AspNetCore.ResponseAutoWrapper</PackageIdPrefix>

src/Cuture.AspNetCore.ResponseAutoWrapper/ResponseAutoWrapMiddleware.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ public ResponseAutoWrapMiddleware(RequestDelegate next,
9595

9696
public async Task InvokeAsync(HttpContext context)
9797
{
98-
if (_ignoreOptionsRequest
99-
&& HttpMethods.IsOptions(context.Request.Method))
98+
if ((_ignoreOptionsRequest
99+
&& HttpMethods.IsOptions(context.Request.Method))
100+
|| context.IsSetDoNotWrapResponse())
100101
{
101102
await _next(context);
102103
return;
@@ -108,7 +109,8 @@ public async Task InvokeAsync(HttpContext context)
108109
}
109110
catch (Exception ex)
110111
{
111-
if (_notCatchExceptions)
112+
if (_notCatchExceptions
113+
|| context.IsSetDoNotWrapResponse())
112114
{
113115
throw;
114116
}
@@ -141,7 +143,8 @@ public async Task InvokeAsync(HttpContext context)
141143
{
142144
if (!context.Response.HasStarted
143145
&& !context.RequestAborted.IsCancellationRequested
144-
&& context.Response.StatusCode != StatusCodes.Status200OK)
146+
&& context.Response.StatusCode != StatusCodes.Status200OK
147+
&& !context.IsSetDoNotWrapResponse())
145148
{
146149
var response = _notOKStatusCodeWrapDelegate(context);
147150
if (response is not null)

0 commit comments

Comments
 (0)