Skip to content

Commit 1ce6e1c

Browse files
committed
Simplify ContentNegotiationMiddleware by using primary constructor and removing redundant field
1 parent 0ddb208 commit 1ce6e1c

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

server/src/Docs.Web/ContentNegotiationMiddleware.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ namespace Docs.Web;
33
/// <summary>
44
/// Middleware that serves .md files when the client sends Accept: text/markdown.
55
/// </summary>
6-
public class ContentNegotiationMiddleware : IMiddleware
6+
public class ContentNegotiationMiddleware(IWebHostEnvironment environment) : IMiddleware
77
{
8-
private readonly IWebHostEnvironment _environment;
9-
10-
public ContentNegotiationMiddleware(IWebHostEnvironment environment)
11-
{
12-
_environment = environment;
13-
}
14-
158
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
169
{
1710
var accept = context.Request.Headers.Accept.ToString();
@@ -22,8 +15,8 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
2215
// Try the exact path with .md extension, then index.md inside the directory
2316
var candidates = new[]
2417
{
25-
Path.Combine(_environment.WebRootPath, requestPath.TrimStart('/') + ".md"),
26-
Path.Combine(_environment.WebRootPath, requestPath.TrimStart('/'), "index.md")
18+
Path.Combine(environment.WebRootPath, requestPath.TrimStart('/') + ".md"),
19+
Path.Combine(environment.WebRootPath, requestPath.TrimStart('/'), "index.md")
2720
};
2821

2922
foreach (var mdPath in candidates)

0 commit comments

Comments
 (0)