From 49c4b0f4c7537e5f120101076d516d25b93abf11 Mon Sep 17 00:00:00 2001 From: "Alecio Furanze (Ale)" Date: Thu, 27 Jun 2024 12:40:15 +0200 Subject: [PATCH] fix. 2nd middleware wasn't called --- src/http/partials/Server/HTTP.MiddlewareDescriptor.cs | 10 ++++------ src/http/partials/Server/HTTP.ServerTo.cs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs b/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs index 77d4df83..e0e8d0cb 100644 --- a/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs +++ b/src/http/partials/Server/HTTP.MiddlewareDescriptor.cs @@ -12,13 +12,12 @@ internal class MiddlewareDescriptor : IHTTP.MiddlewareDescriptor public string Path { get; } public MiddlewareDescriptor Next { get; set; } - public Action - Callback { get; internal set; } + public Action Callback { get; } public bool UseParams { get; } - public MiddlewareDescriptor(string path, bool useParams, - Action callback) + public MiddlewareDescriptor + (string path, bool useParams, Action callback) { Path = path; UseParams = useParams; @@ -28,8 +27,7 @@ public MiddlewareDescriptor(string path, bool useParams, public void Execute(IHTTP.ServerRequest request, IHTTP.ServerResponse response) { - if (Next == null) return; - Next?.Callback(request, response, () => Next?.Execute(request, response)); + if (Next != null) Next.Callback(request, response, () => Next?.Execute(request, response)); } } } diff --git a/src/http/partials/Server/HTTP.ServerTo.cs b/src/http/partials/Server/HTTP.ServerTo.cs index 1de97b5b..997f065d 100644 --- a/src/http/partials/Server/HTTP.ServerTo.cs +++ b/src/http/partials/Server/HTTP.ServerTo.cs @@ -250,8 +250,8 @@ private async Task HandleConnection(HttpListenerContext context) } } - descriptors[0].Callback(request, response, - () => descriptors[0].Next.Execute(request, response)); + var mainDescriptor = descriptors[0]; + mainDescriptor.Callback(request, response, () => mainDescriptor.Execute(request, response)); } }