diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cxx b/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cxx index 9bc3c9de00..c4860c1acb 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cxx +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cxx @@ -94,7 +94,8 @@ http_set_response_status_code( _In_ PCSTR pszReason ) { - return pInProcessHandler->QueryHttpContext()->GetResponse()->SetStatus(statusCode, pszReason); + return pInProcessHandler->QueryHttpContext()->GetResponse()->SetStatus(statusCode, pszReason, 0, 0, nullptr, + true); // fTrySkipCustomErrors } EXTERN_C __MIDL_DECLSPEC_DLLEXPORT diff --git a/test/IISIntegration.FunctionalTests/Inprocess/ResponseHeaderTests.cs b/test/IISIntegration.FunctionalTests/Inprocess/ResponseHeaderTests.cs index d96a0ae850..09e3688fbf 100644 --- a/test/IISIntegration.FunctionalTests/Inprocess/ResponseHeaderTests.cs +++ b/test/IISIntegration.FunctionalTests/Inprocess/ResponseHeaderTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -51,15 +52,30 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests } [ConditionalTheory] - [InlineData(200, "custom", "custom")] - [InlineData(500, "", "Internal Server Error")] - [InlineData(999, "", "")] - public async Task CustomErrorCodeWorks(int code, string reason, string expectedReason) + [InlineData(200, "custom", "custom", null)] + [InlineData(200, "custom", "custom", "Custom body")] + [InlineData(200, "custom", "custom", "")] + + + [InlineData(500, "", "Internal Server Error", null)] + [InlineData(500, "", "Internal Server Error", "Custom body")] + [InlineData(500, "", "Internal Server Error", "")] + + [InlineData(400, "custom", "custom", null)] + [InlineData(400, "", "Bad Request", "Custom body")] + [InlineData(400, "", "Bad Request", "")] + + [InlineData(999, "", "", null)] + [InlineData(999, "", "", "Custom body")] + [InlineData(999, "", "", "")] + public async Task CustomErrorCodeWorks(int code, string reason, string expectedReason, string body) { - var response = await _fixture.Client.GetAsync($"SetCustomErorCode?code={code}&reason={reason}"); + var response = await _fixture.Client.GetAsync($"SetCustomErorCode?code={code}&reason={reason}&writeBody={body != null}&body={body}"); Assert.Equal((HttpStatusCode)code, response.StatusCode); Assert.Equal(expectedReason, response.ReasonPhrase); - Assert.Equal("Body", await response.Content.ReadAsStringAsync()); + + // ReadAsStringAsync returns empty string for empty results + Assert.Equal(body ?? string.Empty, await response.Content.ReadAsStringAsync()); } } } diff --git a/test/WebSites/InProcessWebSite/Startup.cs b/test/WebSites/InProcessWebSite/Startup.cs index 8d0e49d946..3aaba9b44f 100644 --- a/test/WebSites/InProcessWebSite/Startup.cs +++ b/test/WebSites/InProcessWebSite/Startup.cs @@ -214,7 +214,10 @@ namespace IISTestSite var feature = ctx.Features.Get(); feature.ReasonPhrase = ctx.Request.Query["reason"]; feature.StatusCode = int.Parse(ctx.Request.Query["code"]); - await ctx.Response.WriteAsync("Body"); + if (ctx.Request.Query["writeBody"] == "True") + { + await ctx.Response.WriteAsync(ctx.Request.Query["body"]); + } }); } @@ -735,6 +738,5 @@ namespace IISTestSite ctx.RequestServices.GetService().StopApplication(); }); } - } } diff --git a/test/WebSites/InProcessWebSite/web.config b/test/WebSites/InProcessWebSite/web.config index 3e1be0c169..2a9bd223c3 100644 --- a/test/WebSites/InProcessWebSite/web.config +++ b/test/WebSites/InProcessWebSite/web.config @@ -1,10 +1,10 @@ - + - + @@ -13,4 +13,4 @@ - \ No newline at end of file +