diff --git a/src/Femsci.Nyangate.Client/Client.cs b/src/Femsci.Nyangate.Client/Client.cs index 3e2dad3..dc995ef 100644 --- a/src/Femsci.Nyangate.Client/Client.cs +++ b/src/Femsci.Nyangate.Client/Client.cs @@ -11,9 +11,17 @@ public static class Client { public static IServiceCollection AddNyangate(this IServiceCollection c, Action 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!; } diff --git a/src/Nyangate/Filters/ContextFilter.cs b/src/Nyangate/Filters/ContextFilter.cs index 085b514..74efb55 100644 --- a/src/Nyangate/Filters/ContextFilter.cs +++ b/src/Nyangate/Filters/ContextFilter.cs @@ -2,8 +2,10 @@ namespace Nyangate.Filters; public class ContextFilter { - private readonly List _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 _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))) { diff --git a/src/Nyangate/Middleware/Authenticator.cs b/src/Nyangate/Middleware/Authenticator.cs index f74aedb..a03b59d 100644 --- a/src/Nyangate/Middleware/Authenticator.cs +++ b/src/Nyangate/Middleware/Authenticator.cs @@ -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); - } } diff --git a/src/Nyangate/Middleware/HostSelector.cs b/src/Nyangate/Middleware/HostSelector.cs index e4e5ba3..02b07ab 100644 --- a/src/Nyangate/Middleware/HostSelector.cs +++ b/src/Nyangate/Middleware/HostSelector.cs @@ -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(); diff --git a/src/Nyangate/Middleware/Logger.cs b/src/Nyangate/Middleware/Logger.cs index 8f234d6..bc952db 100644 --- a/src/Nyangate/Middleware/Logger.cs +++ b/src/Nyangate/Middleware/Logger.cs @@ -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()); } } diff --git a/src/Nyangate/Middleware/Router.cs b/src/Nyangate/Middleware/Router.cs index e7c8eec..a764d1e 100644 --- a/src/Nyangate/Middleware/Router.cs +++ b/src/Nyangate/Middleware/Router.cs @@ -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; }