Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What makes something be a request feature in ASP.NET Core?

There's one point in ASP.NET Core that I believe I didn't fully understand yet and that is the idea of request features. As explained in the docs:

Feature interfaces define specific HTTP features that a given request may support. Servers define collections of features, and the initial set of features supported by that server, but middleware can be used to enhance these features.

My initial understanding about this was that request features are all things a server should expose to be used on the application pipeline. That is, behaviors that a server should perform like sending a file.

On the other hand, there's, for example, the authentication request feature. Now, I'm not sure authentication falls into this category. It doesn't seem like some server behavior that the application should call, but rather, a concern of the application itself.

This makes me wonder what really makes something be a request feature. So, what makes something be a request feature in ASP.NET Core? Is my initial understanding wrong? What is behind the decision of making something a request feature?

like image 562
user1620696 Avatar asked Jan 25 '16 13:01

user1620696


People also ask

How does ASP.NET Core process a request?

The ASP.NET Core web server will convert the response from the application logic into a raw HTTP response and sends it back to the reverse proxy. The reverse proxy will then send it back to the browser.

What is request in asp net?

When a browser asks for a page from a server, it is called a request. The Request object is used to get information from a visitor.

What are request delegates in ASP.NET Core?

Request delegates are used to build the request pipeline. The request delegates handle each HTTP request. Request delegates are configured using Run, Map, and Use extension methods.


1 Answers

My initial understanding about this was that request features are all things a server should expose to be used on the application pipeline. That is, behaviors that a server should perform like sending a file.

That's one use of http features. It's also a way to augment or light up behaviors on the HttpContext, like buffering, send file, authentication, websockets.

Middleware can also add features specific to that middleware, you can see examples of this:

  • The exception handler middleware flows the exception that occurred via a request feature - https://github.com/aspnet/Diagnostics/blob/dev/src/Microsoft.AspNetCore.Diagnostics.Abstractions/IExceptionHandlerFeature.cs.
  • The routing middleware adds route data to the current http context via a request feature - https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNetCore.Routing.Abstractions/IRoutingFeature.cs

Generally it's a way to flow per request behavior and state from the server, through middleware, to the application.

like image 110
davidfowl Avatar answered Nov 02 '22 23:11

davidfowl