Do not override error responses (#985)

This commit is contained in:
Pavel Krymets 2018-06-27 22:53:30 -07:00 committed by GitHub
parent 32e0d136f2
commit 27780c28ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 12 deletions

View File

@ -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

View File

@ -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());
}
}
}

View File

@ -214,7 +214,10 @@ namespace IISTestSite
var feature = ctx.Features.Get<IHttpResponseFeature>();
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<IApplicationLifetime>().StopApplication();
});
}
}
}

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="inprocess">
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_VALUE" value="foobar" />
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_LONG_VALUE" value="AReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNative" />
@ -13,4 +13,4 @@
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
</configuration>