-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PrefersColorSchemeMiddleware and config setting
- Added `PrefersColorSchemeMiddleware` to handle color scheme headers. - Updated `Program.cs` to conditionally use the new middleware based on `Experimental:UsePrefersColorSchemeHeader` setting. - Modified `appsettings.json` to include `Experimental` section with `UsePrefersColorSchemeHeader` setting.
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/Moonglade.Web/Middleware/PrefersColorSchemeMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Moonglade.Web.Middleware; | ||
|
||
public class PrefersColorSchemeMiddleware(RequestDelegate next) | ||
{ | ||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
context.Response.OnStarting(() => | ||
{ | ||
context.Response.Headers["Accept-CH"] = "Sec-CH-Prefers-Color-Scheme"; | ||
context.Response.Headers["Vary"] = "Sec-CH-Prefers-Color-Scheme"; | ||
context.Response.Headers["Critical-CH"] = "Sec-CH-Prefers-Color-Scheme"; | ||
return Task.CompletedTask; | ||
}); | ||
|
||
await next(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters