state
This commit is contained in:
parent
12648a2028
commit
bae2f9df4d
6 changed files with 25 additions and 15 deletions
|
@ -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!;
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue