You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Web server implementation details related to HTTP requests and responses are defined in interfaces. These interfaces are used by server implementations and middleware to create and modify the application's hosting pipeline.
15
+
The `HttpContext` API that applications and middleware use to process requests has an abstraction layer undernieth it called *feature interfaces*. Each feature interface provides a granular subset of the functionality exposed by `HttpContext`. These interfaces can be added, modified, wrapped, replaced, or even removed by the server or middleware as the request is processed without having to re-implement the entire `HttpContext`. They can also be used to mock functionality when testing.
16
+
17
+
## Feature collections
18
+
19
+
The <xref:Microsoft.AspNetCore.Http.HttpContext.Features> property of `HttpContext` provides access to the collection of feature interfaces for the current request. Since the feature collection is mutable even within the context of a request, middleware can be used to modify the collection and add support for additional features. Some advanced features are only available by accessing the associated interface through the feature collection.
15
20
16
21
## Feature interfaces
17
22
18
-
ASP.NET Core defines a number of HTTP feature interfaces in `Microsoft.AspNetCore.Http.Features` which are used by servers to identify the features they support. The following feature interfaces handle requests and return responses:
23
+
ASP.NET Core defines a number of common HTTP feature interfaces in <xref:Microsoft.AspNetCore.Http.Features?displayProperty=fullName>, which are shared by various servers and middleware to identify the features that they support. Servers and middleware may also provide their own interfaces with additional functionality.
19
24
20
-
`IHttpRequestFeature`
21
-
Defines the structure of an HTTP request, including the protocol, path, query string, headers, and body.
25
+
Most feature interfaces provide optional, light-up functionality, and their associated `HttpContext` APIs provide defaults if the feature isn't present. A few interfaces are indicated in the following content as required because they provide core request and response functionality and must be implemented in order to process the request.
22
26
23
-
`IHttpResponseFeature`
24
-
Defines the structure of an HTTP response, including the status code, headers, and body of the response.
27
+
The following feature interfaces are from <xref:Microsoft.AspNetCore.Http.Features?displayProperty=fullName>:
25
28
26
-
`IHttpAuthenticationFeature`
27
-
Defines support for identifying users based on a `ClaimsPrincipal` and specifying an authentication handler.
29
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpRequestFeature>: Defines the structure of an HTTP request, including the protocol, path, query string, headers, and body. This feature is required in order to process requests.
28
30
29
-
`IHttpUpgradeFeature`
30
-
Defines support for [HTTP Upgrades](https://tools.ietf.org/html/rfc2616.html#section-14.42), which allow the client to specify which additional protocols it would like to use if the server wishes to switch protocols.
31
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpResponseFeature>: Defines the structure of an HTTP response, including the status code, headers, and body of the response. This feature is required in order to process requests.
31
32
32
-
`IHttpBufferingFeature`
33
-
Defines methods for disabling buffering of requests and/or responses.
33
+
::: moniker range=">= aspnetcore-3.0"
34
34
35
-
`IHttpConnectionFeature`
36
-
Defines properties for local and remote addresses and ports.
35
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature>: Defines different ways of writing out the response body, using either a `Stream`, a `PipeWriter`, or a file. This feature is required in order to process requests. This replaces `IHttpResponseFeature.Body` and `IHttpSendFileFeature`.
37
36
38
-
`IHttpRequestLifetimeFeature`
39
-
Defines support for aborting connections, or detecting if a request has been terminated prematurely, such as by a client disconnect.
37
+
::: moniker-end
40
38
41
-
`IHttpSendFileFeature`
42
-
Defines a method for sending files asynchronously.
39
+
<xref:Microsoft.AspNetCore.Http.Features.Authentication.IHttpAuthenticationFeature>: Holds the <xref:System.Security.Claims.ClaimsPrincipal> currently associated with the request.
43
40
44
-
`IHttpWebSocketFeature`
45
-
Defines an API for supporting web sockets.
41
+
<xref:Microsoft.AspNetCore.Http.Features.IFormFeature>: Used to parse and cache incoming HTTP and multipart form submissions.
46
42
47
-
`IHttpRequestIdentifierFeature`
48
-
Adds a property that can be implemented to uniquely identify requests.
43
+
::: moniker range=">= aspnetcore-2.0"
49
44
50
-
`ISessionFeature`
51
-
Defines `ISessionFactory` and `ISession` abstractions for supporting user sessions.
45
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpBodyControlFeature>: Used to control if synchronous IO operations are allowed for the request or response bodies.
52
46
53
-
`ITlsConnectionFeature`
54
-
Defines an API for retrieving client certificates.
47
+
::: moniker-end
48
+
49
+
::: moniker range="< aspnetcore-3.0"
55
50
56
-
`ITlsTokenBindingFeature`
57
-
Defines methods for working with TLS token binding parameters.
51
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpBufferingFeature>: Defines methods for disabling buffering of requests and/or responses.
58
52
59
-
> [!NOTE]
60
-
> `ISessionFeature` isn't a server feature, but is implemented by the `SessionMiddleware` (see [Managing Application State](app-state.md)).
53
+
::: moniker-end
61
54
62
-
## Feature collections
55
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpConnectionFeature>: Defines properties for the connection id and local and remote addresses and ports.
56
+
57
+
::: moniker range=">= aspnetcore-2.0"
58
+
59
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpMaxRequestBodySizeFeature>: Controls the maximum allowed request body size for the current request.
60
+
61
+
::: moniker-end
62
+
63
+
::: moniker range=">= aspnetcore-5.0"
64
+
65
+
`IHttpRequestBodyDetectionFeature`: Indicates if the request can have a body.
66
+
67
+
::: moniker-end
68
+
69
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpRequestIdentifierFeature>: Adds a property that can be implemented to uniquely identify requests.
70
+
71
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpRequestLifetimeFeature>: Defines support for aborting connections or detecting if a request has been terminated prematurely, such as by a client disconnect.
72
+
73
+
::: moniker range=">= aspnetcore-3.0"
74
+
75
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpRequestTrailersFeature>: Provides access to the request trailer headers, if any.
76
+
77
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpResetFeature>: Used to send reset messages for protocols that support them such as HTTP/2 or HTTP/3.
78
+
79
+
::: moniker-end
80
+
81
+
::: moniker range=">= aspnetcore-2.2"
82
+
83
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpResponseTrailersFeature>: Enables the application to provide response trailer headers if supported.
84
+
85
+
::: moniker-end
86
+
87
+
::: moniker range="< aspnetcore-3.0"
88
+
89
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpSendFileFeature>: Defines a method for sending files asynchronously.
90
+
91
+
::: moniker-end
92
+
93
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpUpgradeFeature>: Defines support for [HTTP Upgrades](https://tools.ietf.org/html/rfc2616.html#section-14.42), which allow the client to specify which additional protocols it would like to use if the server wishes to switch protocols.
94
+
95
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpWebSocketFeature>: Defines an API for supporting web sockets.
96
+
97
+
::: moniker range=">= aspnetcore-3.0"
98
+
99
+
<xref:Microsoft.AspNetCore.Http.Features.IHttpsCompressionFeature>: Controls if response compression should be used over HTTPS connections.
100
+
101
+
::: moniker-end
102
+
103
+
<xref:Microsoft.AspNetCore.Http.Features.IItemsFeature>: Stores the <xref:Microsoft.AspNetCore.Http.Features.IItemsFeature.Items> collection for per request application state.
104
+
105
+
<xref:Microsoft.AspNetCore.Http.Features.IQueryFeature>: Parses and caches the query string.
106
+
107
+
::: moniker range=">= aspnetcore-3.0"
108
+
109
+
<xref:Microsoft.AspNetCore.Http.Features.IRequestBodyPipeFeature>: Represents the request body as a <xref:System.IO.Pipelines.PipeReader>.
110
+
111
+
::: moniker-end
112
+
113
+
<xref:Microsoft.AspNetCore.Http.Features.IRequestCookiesFeature>: Parses and caches the request `Cookie` header values.
63
114
64
-
The `Features` property of `HttpContext` provides an interface for getting and setting the available HTTP features for the current request. Since the feature collection is mutable even within the context of a request, middleware can be used to modify the collection and add support for additional features.
115
+
<xref:Microsoft.AspNetCore.Http.Features.IResponseCookiesFeature>: Controls how response cookies are applied to the `Set-Cookie` header.
65
116
66
-
## Middleware and request features
117
+
::: moniker range=">= aspnetcore-2.2"
67
118
68
-
While servers are responsible for creating the feature collection, middleware can both add to this collection and consume features from the collection. For example, the `StaticFileMiddleware` accesses the `IHttpSendFileFeature` feature. If the feature exists, it's used to send the requested static file from its physical path. Otherwise, a slower alternative method is used to send the file. When available, the `IHttpSendFileFeature` allows the operating
69
-
system to open the file and perform a direct kernel mode copy to the network card.
119
+
<xref:Microsoft.AspNetCore.Http.Features.IServerVariablesFeature>: This feature provides access to request server variables such as those provided by IIS.
70
120
71
-
Additionally, middleware can add to the feature collection established by the server. Existing features can even be replaced by middleware, allowing the middleware to augment the functionality of the server. Features added to the collection are available immediately to other middleware or the underlying application itself later in the request pipeline.
121
+
::: moniker-end
122
+
123
+
<xref:Microsoft.AspNetCore.Http.Features.IServiceProvidersFeature>: Provides access to an <xref:System.IServiceProvider> with scoped request services.
72
124
73
-
By combining custom server implementations and specific middleware enhancements, the precise set of features an application requires can be constructed. This allows missing features to be added without requiring a change in server, and ensures only the minimal amount of features are exposed, thus limiting attack surface area and improving performance.
125
+
<xref:Microsoft.AspNetCore.Http.Features.ISessionFeature>: Defines `ISessionFactory`and <xref:Microsoft.AspNetCore.Http.ISession> abstractions for supporting user sessions. `ISessionFeature` is implemented by the <xref:Microsoft.AspNetCore.Session.SessionMiddleware> (see <xref:fundamentals/app-state>).
74
126
75
-
## Summary
127
+
<xref:Microsoft.AspNetCore.Http.Features.ITlsConnectionFeature>: Defines an API for retrieving client certificates.
76
128
77
-
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.
129
+
<xref:Microsoft.AspNetCore.Http.Features.ITlsTokenBindingFeature>: Defines methods for working with TLS token binding parameters.
130
+
131
+
::: moniker range=">= aspnetcore-2.2"
132
+
133
+
<xref:Microsoft.AspNetCore.Http.Features.ITrackingConsentFeature>: Used to query, grant, and withdraw user consent regarding the storage of user information related to site activity and functionality.
134
+
135
+
::: moniker-end
78
136
79
137
## Additional resources
80
138
81
-
*[Servers](xref:fundamentals/servers/index)
82
-
*[Middleware](xref:fundamentals/middleware/index)
83
-
*[Open Web Interface for .NET (OWIN)](xref:fundamentals/owin)
0 commit comments