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

Commit

Permalink
Merge pull request #1668 from khellang/single-status-code-handler
Browse files Browse the repository at this point in the history
Break when status code has been handled
  • Loading branch information
thecodejunkie committed Aug 19, 2015
2 parents eca21b4 + 7bac92f commit bdc5cf4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Nancy/NancyEngine.cs
Expand Up @@ -197,13 +197,23 @@ private void CheckStatusCodeHandler(NancyContext context)
return;
}

foreach (var statusCodeHandler in this.statusCodeHandlers)
var handlers = this.statusCodeHandlers
.Where(x => x.HandlesStatusCode(context.Response.StatusCode, context))
.ToList();

var defaultHandler = handlers
.FirstOrDefault(x => x is DefaultStatusCodeHandler);

var customHandler = handlers
.FirstOrDefault(x => !(x is DefaultStatusCodeHandler));

var handler = customHandler ?? defaultHandler;
if (handler == null)
{
if (statusCodeHandler.HandlesStatusCode(context.Response.StatusCode, context))
{
statusCodeHandler.Handle(context.Response.StatusCode, context);
}
return;
}

handler.Handle(context.Response.StatusCode, context);
}

private Task<NancyContext> InvokeRequestLifeCycle(NancyContext context, CancellationToken cancellationToken, IPipelines pipelines)
Expand Down

0 comments on commit bdc5cf4

Please sign in to comment.