RequestDelegate represents the next step in an ASP.NET Core HTTP pipeline: a function that receives an HttpContext and returns a Task. Middleware stores one in its constructor and invokes it when the current component should pass the request onward. section 31.1.4 section 31.4
Use the delegate to control whether middleware handles a request or continues the pipeline:
- Call _next.Invoke(context), or simply _next(context), when another middleware should handle the request. section 31.4
A middleware branch
A health-check middleware returns plain-text "pong" for requests beginning with /ping. For every other path, it invokes the supplied RequestDelegate, leaving the next pipeline component responsible for the response. section 36.1
Because RequestDelegate is a one-parameter function, tests can supply a small lambda that records whether the next component ran. This makes it possible to verify both delegation and response-producing branches.
