diff --git a/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs b/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs index 391124b6..77d4df83 100644 --- a/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs +++ b/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs @@ -28,7 +28,7 @@ public MiddlewareDescriptor(string path, bool useParams, public void Execute(IHTTP.ServerRequest request, IHTTP.ServerResponse response) { - if(Next == null) return; + if (Next == null) return; Next?.Callback(request, response, () => Next?.Execute(request, response)); } } diff --git a/src/http/partials/Server/HTTP.ServerRequest.cs b/src/http/partials/Server/HTTP.ServerRequest.cs index 728c9872..9680ed2f 100644 --- a/src/http/partials/Server/HTTP.ServerRequest.cs +++ b/src/http/partials/Server/HTTP.ServerRequest.cs @@ -189,7 +189,7 @@ internal ServerRequest(HttpResponseMessage message) Encoding = GetEncodingFromHeader(); var buffer = message.Content.ReadAsByteArrayAsync().Result; - + Body = new Body(buffer, Encoding, Headers); } } @@ -221,7 +221,7 @@ private void SetQueriesFromUri(Uri uri) foreach (var queryName in queryBuilder.AllKeys) Queries.Add(queryName, queryBuilder[queryName]); } - + private Encoding GetEncodingFromHeader() { var comparisonType = StringComparison.InvariantCultureIgnoreCase; diff --git a/src/http/partials/Server/HTTP.ServerTo.cs b/src/http/partials/Server/HTTP.ServerTo.cs index 36c665f7..1de97b5b 100644 --- a/src/http/partials/Server/HTTP.ServerTo.cs +++ b/src/http/partials/Server/HTTP.ServerTo.cs @@ -155,7 +155,7 @@ void AcceptCallback(IAsyncResult result) { if (IsOpened) { - HttpListenerContext context = _listener.EndGetContext(result); + var context = _listener.EndGetContext(result); Task.Run(async () => { @@ -192,17 +192,19 @@ private static string DefaultHtmlBody(string content) private async Task HandleConnection(HttpListenerContext context) { var request = new ServerRequest(context.Request); + var response = new ServerResponse(context.Response); + var notFoundMessage = DefaultHtmlBody($"[{request.Method.Method.ToUpper()}] {request.Path}"); var middlewares = _server.MyMiddleware.Middlewares.ToList(); - Console.WriteLine("Middleware found: " + middlewares.Count); + if (middlewares.Count > 0) { var descriptors = middlewares.FindAll(x => { // allow global middleware - if (x.Path == HTTP.Middleware.GlobalPath) return true; + if (x.Path == Middleware.GlobalPath) return true; if (!x.UseParams) // simple path compare @@ -232,11 +234,9 @@ private async Task HandleConnection(HttpListenerContext context) if (descriptors.Count > 0) { - Console.WriteLine("Middleware des found: " + descriptors.Count); - - int count = descriptors.Count; + var count = descriptors.Count; - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { var descriptor = descriptors[i]; @@ -268,7 +268,7 @@ private async Task HandleConnection(HttpListenerContext context) { // handle all method var handleMethod = - string.Equals(x.Method, HTTP.Map.ALL_MEHOD, StringComparison.CurrentCultureIgnoreCase) + string.Equals(x.Method, Map.ALL_MEHOD, StringComparison.CurrentCultureIgnoreCase) || string.Equals(request.Method.Method, x.Method, StringComparison.CurrentCultureIgnoreCase);