[Breaking change]: Endpoints configured with 'MapFallbackToFile()' now only match 'HEAD' and 'GET' requests
MackinnonBuck opened this issue · comments
Description
The ConsumesAttribute
attribute allows controller actions to specify their supported content types. Starting in .NET 6, if a fallback file endpoint was configured, it could match routes that were discarded due to the request having a different content type than what was specified in an action's ConsumesAttribute
. This was an undesirable change in behavior from .NET 5 that we are partially addressing in .NET 7 by making fallback file endpoints only match GET
and HEAD
requests.
Version
.NET 7 RC2
Previous behavior
Endpoints configured with StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile()
may match requests made with any request method.
New behavior
Endpoints configured with StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile()
will only match HEAD
and GET
requests.
Type of breaking change
- Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
- Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
- Behavioral change: Existing code and binaries may experience different run-time behavior.
Reason for change
This partially reverts larger breaking change accidentally introduced in .NET 6. Since it's highly unusual to expect a fallback file response when making a request with a method other than HEAD
or GET
, we anticipate the impact of this breaking change to be minimal.
Recommended action
If you want fallback file endpoints to match requests with methods other than HEAD
or GET
, you can specify additional HTTP request methods using WithMetadata()
. For example:
endpoints.MapFallbackToFile("index.html")
.WithMetadata(new HttpMethodMetadata(new[] { /* List supported methods here */ }));
Affected APIs
All overloads of StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile()
.