Do not return 200 for exceptions
This commit is contained in:
parent
af96c91584
commit
205fe9daf1
|
|
@ -12,6 +12,7 @@
|
||||||
"commandName": "Executable",
|
"commandName": "Executable",
|
||||||
"executablePath": "$(IISExpressPath)",
|
"executablePath": "$(IISExpressPath)",
|
||||||
"commandLineArgs": "$(IISExpressArguments)",
|
"commandLineArgs": "$(IISExpressArguments)",
|
||||||
|
"nativeDebugging": true,
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
|
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
|
||||||
"ANCM_PATH": "$(TargetDir)$(AncmPath)",
|
"ANCM_PATH": "$(TargetDir)$(AncmPath)",
|
||||||
|
|
|
||||||
|
|
@ -332,10 +332,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
public unsafe void SendResponseHeaders(bool appCompleted)
|
public unsafe void SendResponseHeaders(bool appCompleted)
|
||||||
{
|
{
|
||||||
// Verifies we have sent the statuscode before writing a header
|
// Verifies we have sent the statuscode before writing a header
|
||||||
var reasonPhraseBytes = Encoding.UTF8.GetBytes(ReasonPhrase ?? ReasonPhrases.GetReasonPhrase(StatusCode));
|
var reasonPhrase = string.IsNullOrWhiteSpace(ReasonPhrase) ? ReasonPhrases.GetReasonPhrase(StatusCode) : ReasonPhrase;
|
||||||
|
var reasonPhraseBytes = Encoding.UTF8.GetBytes(reasonPhrase);
|
||||||
|
|
||||||
fixed (byte* pReasonPhrase = reasonPhraseBytes)
|
fixed (byte* pReasonPhrase = reasonPhraseBytes)
|
||||||
{
|
{
|
||||||
|
Debug.Assert((IntPtr)pReasonPhrase != IntPtr.Zero);
|
||||||
// This copies data into the underlying buffer
|
// This copies data into the underlying buffer
|
||||||
NativeMethods.http_set_response_status_code(_pInProcessHandler, (ushort)StatusCode, pReasonPhrase);
|
NativeMethods.http_set_response_status_code(_pInProcessHandler, (ushort)StatusCode, pReasonPhrase);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
Assert.Equal("1", headerValues.First());
|
Assert.Equal("1", headerValues.First());
|
||||||
Assert.Equal("2", headerValues.Last());
|
Assert.Equal("2", headerValues.Last());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ConditionalFact]
|
||||||
|
public async Task ErrorCodeIsSetForExceoptionDuringRequest()
|
||||||
|
{
|
||||||
|
var response = await _fixture.Client.GetAsync("Throw");
|
||||||
|
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
||||||
|
Assert.Equal("Internal Server Error", response.ReasonPhrase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -23,33 +24,16 @@ namespace IISTestSite
|
||||||
{
|
{
|
||||||
public void Configure(IApplicationBuilder app)
|
public void Configure(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.Map("/ServerVariable", ServerVariable);
|
foreach (var method in GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||||
app.Map("/AuthenticationAnonymous", AuthenticationAnonymous);
|
{
|
||||||
app.Map("/AuthenticationRestricted", AuthenticationRestricted);
|
var parameters = method.GetParameters();
|
||||||
app.Map("/AuthenticationForbidden", AuthenticationForbidden);
|
if (method.Name != nameof(Configure) &&
|
||||||
app.Map("/AuthenticationRestrictedNTLM", AuthenticationRestrictedNTLM);
|
parameters.Length == 1 &&
|
||||||
app.Map("/FeatureCollectionSetRequestFeatures", FeatureCollectionSetRequestFeatures);
|
parameters[0].ParameterType == typeof(IApplicationBuilder))
|
||||||
app.Map("/FeatureCollectionSetResponseFeatures", FeatureCollectionSetResponseFeatures);
|
{
|
||||||
app.Map("/FeatureCollectionSetConnectionFeatures", FeatureCollectionSetConnectionFeatures);
|
app.Map("/" + method.Name, innerAppBuilder => method.Invoke(this, new[] { innerAppBuilder }));
|
||||||
app.Map("/HelloWorld", HelloWorld);
|
}
|
||||||
app.Map("/LargeResponseBody", LargeResponseBody);
|
}
|
||||||
app.Map("/ResponseHeaders", ResponseHeaders);
|
|
||||||
app.Map("/ResponseInvalidOrdering", ResponseInvalidOrdering);
|
|
||||||
app.Map("/CheckEnvironmentVariable", CheckEnvironmentVariable);
|
|
||||||
app.Map("/CheckEnvironmentLongValueVariable", CheckEnvironmentLongValueVariable);
|
|
||||||
app.Map("/CheckAppendedEnvironmentVariable", CheckAppendedEnvironmentVariable);
|
|
||||||
app.Map("/CheckRemoveAuthEnvironmentVariable", CheckRemoveAuthEnvironmentVariable);
|
|
||||||
app.Map("/ReadAndWriteSynchronously", ReadAndWriteSynchronously);
|
|
||||||
app.Map("/ReadAndWriteEcho", ReadAndWriteEcho);
|
|
||||||
app.Map("/ReadAndWriteCopyToAsync", ReadAndWriteCopyToAsync);
|
|
||||||
app.Map("/ReadAndWriteEchoTwice", ReadAndWriteEchoTwice);
|
|
||||||
app.Map("/ReadAndWriteSlowConnection", ReadAndWriteSlowConnection);
|
|
||||||
app.Map("/WebsocketRequest", WebsocketRequest);
|
|
||||||
app.Map("/UpgradeFeatureDetection", UpgradeFeatureDetection);
|
|
||||||
app.Map("/TestInvalidReadOperations", TestInvalidReadOperations);
|
|
||||||
app.Map("/TestInvalidWriteOperations", TestInvalidWriteOperations);
|
|
||||||
app.Map("/TestReadOffsetWorks", TestReadOffsetWorks);
|
|
||||||
app.Map("/LargeResponseFile", LargeResponseFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerVariable(IApplicationBuilder app)
|
private void ServerVariable(IApplicationBuilder app)
|
||||||
|
|
@ -229,6 +213,11 @@ namespace IISTestSite
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Throw(IApplicationBuilder app)
|
||||||
|
{
|
||||||
|
app.Run(ctx => { throw new Exception(); });
|
||||||
|
}
|
||||||
|
|
||||||
private void HelloWorld(IApplicationBuilder app)
|
private void HelloWorld(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.Run(async ctx =>
|
app.Run(async ctx =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue