diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs index bd0f708b9..b77d9ff97 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs @@ -3,5 +3,7 @@ public static class AbpHttpWrapConsts { public const string AbpWrapResult = "_AbpWrapResult"; + + public const string AbpDontWrapResult = "_AbpDontWrapResult"; } } diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs index 950aabe49..c3131bcf8 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs @@ -44,6 +44,11 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper protected virtual bool CheckForBase(FilterContext context) { + if (context.HttpContext.Request.Headers.ContainsKey(AbpHttpWrapConsts.AbpDontWrapResult)) + { + return false; + } + if (context.ActionDescriptor is ControllerActionDescriptor descriptor) { if (!context.ActionDescriptor.HasObjectResult()) diff --git a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs index 63b37f1dd..8cf666678 100644 --- a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs +++ b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs @@ -11,6 +11,16 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results { public class WrapResultController_Tests : AbpAspNetCoreMvcTestBase { + [Fact] + public async Task Should_Return_Not_Wrap_Result_For_Request_Headers() + { + RequestHeaders.Add(AbpHttpWrapConsts.AbpDontWrapResult, "true"); + + var result = await GetResponseAsObjectAsync("/api/wrap-result-test/wrap"); + result.ShouldNotBeNull(); + result.Name.ShouldBe("Wrap"); + } + [Fact] public async Task Should_Return_Not_Wrap_Result_For_Abp_Remote_Stream_Content() { diff --git a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Tests/LINGYUN/Abp/AspNetCore/AbpAspNetCoreTestBase.cs b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Tests/LINGYUN/Abp/AspNetCore/AbpAspNetCoreTestBase.cs index 90217b80c..e80508136 100644 --- a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Tests/LINGYUN/Abp/AspNetCore/AbpAspNetCoreTestBase.cs +++ b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Tests/LINGYUN/Abp/AspNetCore/AbpAspNetCoreTestBase.cs @@ -1,6 +1,8 @@ using Microsoft.Net.Http.Headers; using Shouldly; +using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Net; using System.Net.Http; using System.Text.Json; @@ -17,15 +19,22 @@ namespace LINGYUN.Abp.AspNetCore public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreIntegratedTestBase where TStartup : class { - protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) + protected IDictionary RequestHeaders { get; } + + protected AbpAspNetCoreTestBase() + { + RequestHeaders = new Dictionary(); + } + + protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, bool xmlHttpRequest = false) { - var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); + var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode, xmlHttpRequest); return JsonSerializer.Deserialize(strResponse, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); } - protected virtual async Task GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) + protected virtual async Task GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, bool xmlHttpRequest = false) { - using (var response = await GetResponseAsync(url, expectedStatusCode)) + using (var response = await GetResponseAsync(url, expectedStatusCode, xmlHttpRequest)) { return await response.Content.ReadAsStringAsync(); } @@ -40,6 +49,10 @@ namespace LINGYUN.Abp.AspNetCore { requestMessage.Headers.Add(HeaderNames.XRequestedWith, "XMLHttpRequest"); } + foreach (var header in RequestHeaders) + { + requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value); + } var response = await Client.SendAsync(requestMessage); response.StatusCode.ShouldBe(expectedStatusCode); return response;