Fixing issues with the route preprocess and postprocess events.
This commit is contained in:
parent
bf254489b8
commit
fcbaaf133c
@ -14,7 +14,7 @@
|
|||||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<Version>1.0.5</Version>
|
<Version>1.0.6</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json">
|
<PackageReference Include="Newtonsoft.Json">
|
||||||
|
@ -114,23 +114,24 @@ namespace MontoyaTech.Rest.Net
|
|||||||
bool handled = false;
|
bool handled = false;
|
||||||
bool close = true;
|
bool close = true;
|
||||||
string[] arguments = null;
|
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))
|
if (this.Routes[i].Method.ToUpper() == ctx.Request.HttpMethod.ToUpper() && RouteMatcher.Matches(ctx.Request.Url.AbsolutePath, this.Routes[i].Syntax, out arguments))
|
||||||
{
|
{
|
||||||
handled = true;
|
handled = true;
|
||||||
close = this.Routes[i].CloseResponse;
|
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.
|
//Make sure if the route fails we don't die here, just set the response to internal server error.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -141,18 +142,18 @@ namespace MontoyaTech.Rest.Net
|
|||||||
ctx.Response.WithStatus(HttpStatusCode.InternalServerError);
|
ctx.Response.WithStatus(HttpStatusCode.InternalServerError);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Post process the route context.
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (this.PostprocessEvent != null)
|
|
||||||
this.PostprocessEvent.Invoke(context);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Post process the route context.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (this.PostprocessEvent != null)
|
||||||
|
this.PostprocessEvent.Invoke(context);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
if (!handled)
|
if (!handled)
|
||||||
ctx.Response.WithStatus(HttpStatusCode.BadRequest);
|
ctx.Response.WithStatus(HttpStatusCode.BadRequest);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user