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

Commit e716532

Browse files
khellangthecodejunkie
authored andcommitted
Make sure we keep ReasonPhrase from existing Response
1 parent 0f22838 commit e716532

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/Nancy/ErrorHandling/DefaultStatusCodeHandler.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ public void Handle(HttpStatusCode statusCode, NancyContext context)
7171
return;
7272
}
7373

74-
// Reset negotiation context to avoid any downstream cast exceptions
74+
Response existingResponse = null;
75+
76+
if (context.Response != null)
77+
{
78+
existingResponse = context.Response;
79+
}
80+
81+
// Reset negotiation context to avoid any downstream cast exceptions
7582
// from swapping a view model with a `DefaultStatusCodeHandlerResult`
7683
context.NegotiationContext = new NegotiationContext();
7784

@@ -80,6 +87,11 @@ public void Handle(HttpStatusCode statusCode, NancyContext context)
8087
{
8188
context.Response = this.responseNegotiator.NegotiateResponse(result, context);
8289
context.Response.StatusCode = statusCode;
90+
91+
if (existingResponse != null)
92+
{
93+
context.Response.ReasonPhrase = existingResponse.ReasonPhrase;
94+
}
8395
return;
8496
}
8597
catch (ViewNotFoundException)

0 commit comments

Comments
 (0)