ln.http/ln.http/HttpContext.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2022-02-07 09:29:30 +01:00
using ln.http.router;
namespace ln.http
{
public class HttpContext
{
2022-05-28 19:17:00 +02:00
public HttpServer HttpServer { get; }
2022-02-07 09:29:30 +01:00
public HttpRequest Request { get; set; }
public HttpResponse Response { get; set; }
public HttpPrincipal AuthenticatedPrincipal { get; private set; }
2022-05-28 19:14:57 +02:00
2022-05-28 19:17:00 +02:00
public HttpContext(HttpServer httpServer)
2022-05-28 19:14:57 +02:00
{
HttpServer = httpServer;
}
2022-05-28 19:17:00 +02:00
public HttpContext(HttpServer httpServer, HttpRequest httpRequest) : this(httpServer)
2022-05-28 19:14:57 +02:00
{
Request = httpRequest;
RoutableUri = httpRequest.RequestUri.AbsolutePath;
}
2022-02-07 09:29:30 +01:00
public string RoutableUri { get; set; }
2022-05-28 19:17:00 +02:00
public bool Authenticate()
2022-02-07 09:29:30 +01:00
{
2022-05-28 19:17:00 +02:00
foreach (var authenticationSource in HttpServer.AuthenticationSources)
2022-02-07 09:29:30 +01:00
{
2022-05-28 19:17:00 +02:00
if (authenticationSource.AuthenticatePrincipal(this, out HttpPrincipal httpPrincipal))
{
AuthenticatedPrincipal = httpPrincipal;
return true;
}
2022-02-07 09:29:30 +01:00
}
return false;
}
public void DeAuthenticate() => AuthenticatedPrincipal = null;
}
}