Skip to content

Commit 7416f71

Browse files
committed
Allow file middlewares to run if there's an endpoint with a null request delegate #42413
1 parent 0db136d commit 7416f71

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public DefaultFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingE
5959
/// <returns></returns>
6060
public Task Invoke(HttpContext context)
6161
{
62-
if (context.GetEndpoint() == null
62+
if (context.GetEndpoint()?.RequestDelegate == null
6363
&& Helpers.IsGetOrHeadMethod(context.Request.Method)
6464
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out var subpath))
6565
{

src/Middleware/StaticFiles/src/DirectoryBrowserMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public DirectoryBrowserMiddleware(RequestDelegate next, IWebHostEnvironment host
7575
/// <returns></returns>
7676
public Task Invoke(HttpContext context)
7777
{
78-
// Check if the URL matches any expected paths, skip if an endpoint was selected
79-
if (context.GetEndpoint() == null
78+
// Check if the URL matches any expected paths, skip if an endpoint with a request delegate was selected
79+
if (context.GetEndpoint()?.RequestDelegate == null
8080
&& Helpers.IsGetOrHeadMethod(context.Request.Method)
8181
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out var subpath)
8282
&& TryGetDirectoryInfo(subpath, out var contents))

src/Middleware/StaticFiles/src/StaticFileMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public StaticFileMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv
6666
/// <returns></returns>
6767
public Task Invoke(HttpContext context)
6868
{
69-
if (!ValidateNoEndpoint(context))
69+
if (!ValidateNoEndpointDelegate(context))
7070
{
7171
_logger.EndpointMatched();
7272
}
@@ -91,8 +91,8 @@ public Task Invoke(HttpContext context)
9191
return _next(context);
9292
}
9393

94-
// Return true because we only want to run if there is no endpoint.
95-
private static bool ValidateNoEndpoint(HttpContext context) => context.GetEndpoint() == null;
94+
// Return true because we only want to run if there is no endpoint delegate.
95+
private static bool ValidateNoEndpointDelegate(HttpContext context) => context.GetEndpoint()?.RequestDelegate == null;
9696

9797
private static bool ValidateMethod(HttpContext context)
9898
{

0 commit comments

Comments
 (0)