Test more things
This commit is contained in:
parent
205fe9daf1
commit
f6f5e575fb
|
|
@ -332,9 +332,10 @@ 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 reasonPhrase = string.IsNullOrWhiteSpace(ReasonPhrase) ? ReasonPhrases.GetReasonPhrase(StatusCode) : ReasonPhrase;
|
var reasonPhrase = string.IsNullOrEmpty(ReasonPhrase) ? ReasonPhrases.GetReasonPhrase(StatusCode) : ReasonPhrase;
|
||||||
var reasonPhraseBytes = Encoding.UTF8.GetBytes(reasonPhrase);
|
var reasonPhraseBytes = new byte [reasonPhrase.Length + 1];
|
||||||
|
Encoding.ASCII.GetBytes(reasonPhrase, 0, reasonPhrase.Length, reasonPhraseBytes, 0);
|
||||||
|
|
||||||
fixed (byte* pReasonPhrase = reasonPhraseBytes)
|
fixed (byte* pReasonPhrase = reasonPhraseBytes)
|
||||||
{
|
{
|
||||||
Debug.Assert((IntPtr)pReasonPhrase != IntPtr.Zero);
|
Debug.Assert((IntPtr)pReasonPhrase != IntPtr.Zero);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
||||||
|
<ProjectReference Include="..\IISTestSite\IISTestSite.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ 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]
|
[ConditionalFact]
|
||||||
public async Task ErrorCodeIsSetForExceoptionDuringRequest()
|
public async Task ErrorCodeIsSetForExceoptionDuringRequest()
|
||||||
{
|
{
|
||||||
|
|
@ -48,5 +48,17 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
||||||
Assert.Equal("Internal Server Error", response.ReasonPhrase);
|
Assert.Equal("Internal Server Error", response.ReasonPhrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ConditionalTheory]
|
||||||
|
[InlineData(1, "custom", "custom")]
|
||||||
|
[InlineData(500, "", "Internal Server Error")]
|
||||||
|
[InlineData(999, "", "")]
|
||||||
|
public async Task CustomErrorCodeWorks(int code, string reason, string expectedReason)
|
||||||
|
{
|
||||||
|
var response = await _fixture.Client.GetAsync($"SetCustomErorCode?code={code}&reason={reason}");
|
||||||
|
Assert.Equal((HttpStatusCode)code, response.StatusCode);
|
||||||
|
Assert.Equal(expectedReason, response.ReasonPhrase);
|
||||||
|
Assert.Equal("Body", await response.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,16 @@ namespace IISTestSite
|
||||||
app.Run(ctx => { throw new Exception(); });
|
app.Run(ctx => { throw new Exception(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetCustomErorCode(IApplicationBuilder app)
|
||||||
|
{
|
||||||
|
app.Run(async ctx => {
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void HelloWorld(IApplicationBuilder app)
|
private void HelloWorld(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.Run(async ctx =>
|
app.Run(async ctx =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue