diff --git a/uhttpsharp-demo/packages.config b/uhttpsharp-demo/packages.config index 639150b..b39b0bc 100644 --- a/uhttpsharp-demo/packages.config +++ b/uhttpsharp-demo/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/uhttpsharp-demo/uhttpsharp.Demo.csproj b/uhttpsharp-demo/uhttpsharp.Demo.csproj index fb380e5..f1d50ef 100644 --- a/uhttpsharp-demo/uhttpsharp.Demo.csproj +++ b/uhttpsharp-demo/uhttpsharp.Demo.csproj @@ -39,13 +39,11 @@ false - - False - ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll + + ..\..\..\NuGetPackages\log4net.2.0.6\lib\net45-full\log4net.dll - - False - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + + ..\..\..\NuGetPackages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/uhttpsharp.Tests/packages.config b/uhttpsharp.Tests/packages.config index 02801fe..913d607 100644 --- a/uhttpsharp.Tests/packages.config +++ b/uhttpsharp.Tests/packages.config @@ -1,5 +1,7 @@  + + diff --git a/uhttpsharp.Tests/uhttpsharp.Tests.csproj b/uhttpsharp.Tests/uhttpsharp.Tests.csproj index 5fa6850..b704faa 100644 --- a/uhttpsharp.Tests/uhttpsharp.Tests.csproj +++ b/uhttpsharp.Tests/uhttpsharp.Tests.csproj @@ -34,6 +34,14 @@ 4 + + ..\..\..\NuGetPackages\log4net.2.0.6\lib\net45-full\log4net.dll + True + + + ..\..\..\NuGetPackages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True + ..\packages\NSubstitute.1.8.1.0\lib\net45\NSubstitute.dll diff --git a/uhttpsharp/Handlers/HttpRouter.cs b/uhttpsharp/Handlers/HttpRouter.cs index c6a7394..f24d5a5 100644 --- a/uhttpsharp/Handlers/HttpRouter.cs +++ b/uhttpsharp/Handlers/HttpRouter.cs @@ -26,6 +26,8 @@ public class HttpRouter : IHttpRequestHandler { private readonly IDictionary _handlers = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + private readonly static string StateLevelPropertyName = "HttpRouteLevel"; + public HttpRouter With(string function, IHttpRequestHandler handler) { _handlers.Add(function, handler); @@ -37,9 +39,16 @@ public Task Handle(IHttpContext context, Func nextHandler) { string function = string.Empty; - if (context.Request.RequestParameters.Length > 0) + int index = GetRouteLevel(context.State); + + if (context.Request.RequestParameters.Length > 0 && index < context.Request.RequestParameters.Length) { - function = context.Request.RequestParameters[0]; + function = context.Request.RequestParameters[index]; + if (!string.IsNullOrEmpty(function)) + { + //we are handling this path + IncreaseRouteLevel(context.State); + } } IHttpRequestHandler value; @@ -52,5 +61,19 @@ public Task Handle(IHttpContext context, Func nextHandler) // Route not found, Call next. return nextHandler(); } + + private int GetRouteLevel(dynamic state) + { + if (!((IDictionary)state).ContainsKey(StateLevelPropertyName)) + { + state.HttpRouteLevel = 0; + } + return state.HttpRouteLevel; + } + + private void IncreaseRouteLevel(dynamic state) + { + state.HttpRouteLevel = state.HttpRouteLevel + 1; + } } -} \ No newline at end of file +} diff --git a/uhttpsharp/packages.config b/uhttpsharp/packages.config index b7ba33b..0b3580f 100644 --- a/uhttpsharp/packages.config +++ b/uhttpsharp/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/uhttpsharp/uhttpsharp.csproj b/uhttpsharp/uhttpsharp.csproj index 424e233..b899c23 100644 --- a/uhttpsharp/uhttpsharp.csproj +++ b/uhttpsharp/uhttpsharp.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties uhttpsharp uhttpsharp - v4.5 + v4.8 512 ..\ @@ -36,9 +36,8 @@ false - - False - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + + ..\..\..\NuGetPackages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll