Files
mixtape/zero.Web/ZeroMiddleware.cs
T
2020-04-15 14:09:52 +02:00

74 lines
2.0 KiB
C#

using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using zero.Core;
namespace zero.Web
{
public class ZeroMiddleware
{
private RequestDelegate Next { get; set; }
private ZeroOptions Options { get; set; }
public ZeroMiddleware(RequestDelegate next, ZeroOptions options)
{
Next = next;
Options = options;
}
public async Task Invoke(HttpContext httpContext)
{
await httpContext.Response.WriteAsync("from zero");
//var context = null; // new AspNetCoreDashboardContext(_storage, _options, httpContext);
//var findResult = Routes.FindDispatcher(httpContext.Request.Path.Value);
//if (findResult == null)
//{
// await Next.Invoke(httpContext);
// return;
//}
// ReSharper disable once LoopCanBeConvertedToQuery
//foreach (var filter in Options.Authorization)
//{
// if (!filter.Authorize(context))
// {
// var isAuthenticated = httpContext.User?.Identity?.IsAuthenticated;
// httpContext.Response.StatusCode = isAuthenticated == true
// ? (int)HttpStatusCode.Forbidden
// : (int)HttpStatusCode.Unauthorized;
// return;
// }
//}
//if (!_options.IgnoreAntiforgeryToken)
//{
// var antiforgery = httpContext.RequestServices.GetService<IAntiforgery>();
// if (antiforgery != null)
// {
// var requestValid = await antiforgery.IsRequestValidAsync(httpContext);
// if (!requestValid)
// {
// // Invalid or missing CSRF token
// httpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
// return;
// }
// }
//}
//context.UriMatch = findResult.Item2;
//await findResult.Item1.Dispatch(context);
}
}
}