Test more things

This commit is contained in:
Pavel Krymets 2018-03-22 13:11:29 -07:00
parent 205fe9daf1
commit f6f5e575fb
4 changed files with 28 additions and 4 deletions

View File

@ -332,9 +332,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
public unsafe void SendResponseHeaders(bool appCompleted)
{
// Verifies we have sent the statuscode before writing a header
var reasonPhrase = string.IsNullOrWhiteSpace(ReasonPhrase) ? ReasonPhrases.GetReasonPhrase(StatusCode) : ReasonPhrase;
var reasonPhraseBytes = Encoding.UTF8.GetBytes(reasonPhrase);
var reasonPhrase = string.IsNullOrEmpty(ReasonPhrase) ? ReasonPhrases.GetReasonPhrase(StatusCode) : ReasonPhrase;
var reasonPhraseBytes = new byte [reasonPhrase.Length + 1];
Encoding.ASCII.GetBytes(reasonPhrase, 0, reasonPhrase.Length, reasonPhraseBytes, 0);
fixed (byte* pReasonPhrase = reasonPhraseBytes)
{
Debug.Assert((IntPtr)pReasonPhrase != IntPtr.Zero);

View File

@ -10,6 +10,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
<ProjectReference Include="..\IISTestSite\IISTestSite.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
Assert.Equal("1", headerValues.First());
Assert.Equal("2", headerValues.Last());
}
[ConditionalFact]
public async Task ErrorCodeIsSetForExceoptionDuringRequest()
{
@ -48,5 +48,17 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
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());
}
}
}

View File

@ -218,6 +218,16 @@ namespace IISTestSite
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)
{
app.Run(async ctx =>