Skip to content

Commit

Permalink
fix. 2nd middleware wasn't called
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Jun 27, 2024
1 parent 0db4105 commit 49c4b0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/http/partials/Server/HTTP.MiddlewareDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ internal class MiddlewareDescriptor : IHTTP.MiddlewareDescriptor
public string Path { get; }
public MiddlewareDescriptor Next { get; set; }

public Action<IHTTP.ServerRequest, IHTTP.ServerResponse, Action>
Callback { get; internal set; }
public Action<IHTTP.ServerRequest, IHTTP.ServerResponse, Action> Callback { get; }

public bool UseParams { get; }

public MiddlewareDescriptor(string path, bool useParams,
Action<IHTTP.ServerRequest, IHTTP.ServerResponse, Action> callback)
public MiddlewareDescriptor
(string path, bool useParams, Action<IHTTP.ServerRequest, IHTTP.ServerResponse, Action> callback)
{
Path = path;
UseParams = useParams;
Expand All @@ -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));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/http/partials/Server/HTTP.ServerTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 49c4b0f

Please sign in to comment.