This commit is contained in:
femsci 2023-12-06 17:29:52 +01:00
parent 12648a2028
commit bae2f9df4d
Signed by: femsci
GPG key ID: 08F7911F0E650C67
6 changed files with 25 additions and 15 deletions

View file

@ -11,9 +11,17 @@ public static class Client
{
public static IServiceCollection AddNyangate(this IServiceCollection c, Action<NyangateClientOptions> options)
{
NyangateClientOptions opts = new();
NyangateClientOptions opts = new()
{
Hostname = ""
};
options.Invoke(opts);
if (opts.Hostname == null)
{
throw new ArgumentNullException(nameof(opts.Hostname), "Hostname cannot be null.");
}
throw new NotImplementedException();
}
@ -26,5 +34,5 @@ public static class Client
public class NyangateClientOptions
{
public string Hostname { get; set; } = null!;
}

View file

@ -2,8 +2,10 @@ namespace Nyangate.Filters;
public class ContextFilter
{
private readonly List<IFilter> _filters = typeof(IFilter).Assembly.GetTypes().Where(t => t.IsAssignableFrom(typeof(IFilter))).Select(t => (IFilter)Activator.CreateInstance(t)!).ToList();
public void ApplyAll(FilterType type, HttpContext ctx)
private readonly List<IFilter> _filters = typeof(IFilter).Assembly.GetTypes().Where(t => t.IsAssignableFrom(typeof(IFilter)))
.Select(t => (IFilter)Activator.CreateInstance(t)!).ToList();
public void ApplyFor(FilterType type, HttpContext ctx)
{
foreach (var filter in _filters.Where(f => f.Type.HasFlag(type)))
{

View file

@ -9,9 +9,8 @@ public class Authenticator
_next = next;
}
public async Task Invoke(HttpContext ctx)
{
public async Task Invoke(HttpContext ctx) =>
//LDAP or Oauth2
//do smth
await _next.Invoke(ctx);
}
}

View file

@ -20,6 +20,7 @@ public class HostSelector
if (host is null)
{
//TODO: Not found handler
ctx.Response.StatusCode = 404;
await ctx.Response.WriteAsync("meowless~");
await ctx.Response.CompleteAsync();

View file

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Nyangate.Middleware;
public class Logger
@ -17,7 +12,11 @@ public class Logger
public async Task Invoke(HttpContext ctx)
{
Console.WriteLine(ctx.ToString());
var start = DateTime.Now;
await _next.Invoke(ctx);
var end = DateTime.Now;
var delta = end - start;
int status = ctx.Response.StatusCode;
Console.WriteLine(ctx.ToString());
}
}

View file

@ -1,5 +1,6 @@
using Microsoft.Extensions.Primitives;
using Nyangate.Filters;
using Nyangate.Lib.Data;
using Nyangate.Lib.Http;
using Nyangate.Services;
@ -21,12 +22,12 @@ namespace Nyangate.Middleware
string hostname = ctx.Request.Host.Host;
//check ctx.Request.IsHttps if strict https required
var host = _map.Get(hostname) ?? _map.GetFallback();
if (host is null)
if ((ctx.Features[typeof(ServerHost)] ?? _map.GetFallback()) is not ServerHost host)
{
ctx.Response.StatusCode = 404;
await ctx.Response.WriteAsync("meowless~");
//TODO: Not found handler
await ctx.Response.WriteAsync("meowless²~");
await ctx.Response.CompleteAsync();
return;
}