lampac/Lampac/Engine/Middlewares/AlwaysRjson.cs
lampac-talks f843f04fd4 chore: initial commit 154.3
Signed-off-by: lampac-talks <lampac-talks@users.noreply.github.com>
2026-01-30 16:23:09 +03:00

43 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.WebUtilities;
using Shared;
using System;
using System.Threading.Tasks;
namespace Lampac.Engine.Middlewares
{
public class AlwaysRjson
{
private readonly RequestDelegate _next;
public AlwaysRjson(RequestDelegate next)
{
_next = next;
}
public Task Invoke(HttpContext context)
{
if (!AppInit.conf.always_rjson)
return _next(context);
var builder = new QueryBuilder();
foreach (var kv in QueryHelpers.ParseQuery(context.Request.QueryString.HasValue ? context.Request.QueryString.Value : string.Empty))
{
if (string.Equals(kv.Key, "rjson", StringComparison.OrdinalIgnoreCase))
continue;
foreach (var value in kv.Value)
builder.Add(kv.Key, value);
}
builder.Add("rjson", "true");
context.Request.QueryString = builder.ToQueryString();
return _next(context);
}
}
}