Configuring the HTTP Request Pipeline
Learn about the setup of the HTTP pipeline in ASP.NET Core, detailing the role of delegates, middleware, and key extension methods.
Setting up the HTTP pipeline
After building the web application and its services, the next statements configure the HTTP pipeline, through which HTTP requests and responses flow in and out. The pipeline comprises a connected sequence of delegates that can perform processing and then decide to either return a response themselves or pass processing on to the next delegate in the pipeline. Responses that come back can also be manipulated.
Defining delegates
Delegates define a method signature that a delegate implementation can plug into. We might want to refer back to Implementing Interfaces and Inheriting Classes to refresh delegates’ understanding. The delegate for the HTTP request pipeline is simple, as shown in the following code:
public delegate Task RequestDelegate(HttpContext context);
We can see that the input parameter is an HttpContext
. This provides access to everything we need to process the incoming HTTP request, including the URL path, query string parameters, cookies, and user agent. These delegates are often called middleware because they sit between the browser client and the website or web service.
Methods used to configure middleware delegates
Middleware delegates are configured using one of the following methods or a custom method that calls them itself: