diff --git a/Rest.Net/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net/Rest.Net.csproj index 0377318..c5cc1d5 100644 --- a/Rest.Net/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net/Rest.Net.csproj @@ -14,7 +14,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.0.5 + 1.0.6 diff --git a/Rest.Net/Rest.Net/RouteListener.cs b/Rest.Net/Rest.Net/RouteListener.cs index ff022a4..b54a348 100644 --- a/Rest.Net/Rest.Net/RouteListener.cs +++ b/Rest.Net/Rest.Net/RouteListener.cs @@ -114,23 +114,24 @@ namespace MontoyaTech.Rest.Net bool handled = false; bool close = true; string[] arguments = null; - for (int i = 0; i < this.Routes.Count; i++) + + var context = new RouteContext(ctx.Request, ctx.Response); + + //Preprocess the route context, if it returns false, then we have to not invoke the route. + try + { + if (this.PreprocessEvent != null && !this.PreprocessEvent.Invoke(context)) + handled = true; + } + catch { } + + for (int i = 0; i < this.Routes.Count && !handled; i++) { if (this.Routes[i].Method.ToUpper() == ctx.Request.HttpMethod.ToUpper() && RouteMatcher.Matches(ctx.Request.Url.AbsolutePath, this.Routes[i].Syntax, out arguments)) { handled = true; close = this.Routes[i].CloseResponse; - var context = new RouteContext(ctx.Request, ctx.Response); - - //Preprocess the route context, if it returns false, then we have to not invoke the route. - try - { - if (this.PreprocessEvent != null && !this.PreprocessEvent.Invoke(context)) - break; - } - catch { } - //Make sure if the route fails we don't die here, just set the response to internal server error. try { @@ -141,18 +142,18 @@ namespace MontoyaTech.Rest.Net ctx.Response.WithStatus(HttpStatusCode.InternalServerError); } - //Post process the route context. - try - { - if (this.PostprocessEvent != null) - this.PostprocessEvent.Invoke(context); - } - catch { } - break; } } + //Post process the route context. + try + { + if (this.PostprocessEvent != null) + this.PostprocessEvent.Invoke(context); + } + catch { } + if (!handled) ctx.Response.WithStatus(HttpStatusCode.BadRequest);