Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Make sure we keep ReasonPhrase from existing Response
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang authored and thecodejunkie committed Dec 14, 2015
1 parent 0f22838 commit e716532
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Nancy/ErrorHandling/DefaultStatusCodeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public void Handle(HttpStatusCode statusCode, NancyContext context)
return;
}

// Reset negotiation context to avoid any downstream cast exceptions
Response existingResponse = null;

if (context.Response != null)
{
existingResponse = context.Response;
}

// Reset negotiation context to avoid any downstream cast exceptions
// from swapping a view model with a `DefaultStatusCodeHandlerResult`
context.NegotiationContext = new NegotiationContext();

Expand All @@ -80,6 +87,11 @@ public void Handle(HttpStatusCode statusCode, NancyContext context)
{
context.Response = this.responseNegotiator.NegotiateResponse(result, context);
context.Response.StatusCode = statusCode;

if (existingResponse != null)
{
context.Response.ReasonPhrase = existingResponse.ReasonPhrase;
}
return;
}
catch (ViewNotFoundException)
Expand Down

0 comments on commit e716532

Please sign in to comment.