Do not override error responses (#985)
This commit is contained in:
parent
32e0d136f2
commit
27780c28ba
|
|
@ -94,7 +94,8 @@ http_set_response_status_code(
|
||||||
_In_ PCSTR pszReason
|
_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
|
EXTERN_C __MIDL_DECLSPEC_DLLEXPORT
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -51,15 +52,30 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[InlineData(200, "custom", "custom")]
|
[InlineData(200, "custom", "custom", null)]
|
||||||
[InlineData(500, "", "Internal Server Error")]
|
[InlineData(200, "custom", "custom", "Custom body")]
|
||||||
[InlineData(999, "", "")]
|
[InlineData(200, "custom", "custom", "")]
|
||||||
public async Task CustomErrorCodeWorks(int code, string reason, string expectedReason)
|
|
||||||
|
|
||||||
|
[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((HttpStatusCode)code, response.StatusCode);
|
||||||
Assert.Equal(expectedReason, response.ReasonPhrase);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,10 @@ namespace IISTestSite
|
||||||
var feature = ctx.Features.Get<IHttpResponseFeature>();
|
var feature = ctx.Features.Get<IHttpResponseFeature>();
|
||||||
feature.ReasonPhrase = ctx.Request.Query["reason"];
|
feature.ReasonPhrase = ctx.Request.Query["reason"];
|
||||||
feature.StatusCode = int.Parse(ctx.Request.Query["code"]);
|
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();
|
ctx.RequestServices.GetService<IApplicationLifetime>().StopApplication();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<system.webServer>
|
<system.webServer>
|
||||||
<handlers>
|
<handlers>
|
||||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||||
</handlers>
|
</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>
|
<environmentVariables>
|
||||||
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_VALUE" value="foobar" />
|
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_VALUE" value="foobar" />
|
||||||
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_LONG_VALUE" value="AReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNative" />
|
<environmentVariable name="ASPNETCORE_INPROCESS_TESTING_LONG_VALUE" value="AReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNativeAReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNative" />
|
||||||
|
|
@ -13,4 +13,4 @@
|
||||||
</environmentVariables>
|
</environmentVariables>
|
||||||
</aspNetCore>
|
</aspNetCore>
|
||||||
</system.webServer>
|
</system.webServer>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue