rdt-client/server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs

32 lines
No EOL
832 B
C#

using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace RdtClient.Service.Middleware
{
public class AuthorizeMiddleware
{
readonly RequestDelegate _next;
public AuthorizeMiddleware(RequestDelegate next)
{
_next = next;
}
/// <summary>
/// Return a 403 instead of a 401, it's quirk that QBittorrent has.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task Invoke(HttpContext context)
{
await _next(context);
if (context.Response.StatusCode == (Int32) HttpStatusCode.Unauthorized)
{
context.Response.StatusCode = (Int32) HttpStatusCode.Forbidden;
}
}
}
}