ln.http/ln.http/HttpContext.cs

36 lines
1.0 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:14:57 +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
public HttpContext(HTTPServer httpServer)
{
HttpServer = httpServer;
}
public HttpContext(HTTPServer httpServer, HttpRequest httpRequest) : this(httpServer)
{
Request = httpRequest;
RoutableUri = httpRequest.RequestUri.AbsolutePath;
}
2022-02-07 09:29:30 +01:00
public string RoutableUri { get; set; }
public bool Authenticate(HttpAuthenticationDelegate authenticationDelegate)
{
if (authenticationDelegate(this, out HttpPrincipal principal))
{
AuthenticatedPrincipal = principal;
return true;
}
return false;
}
public void DeAuthenticate() => AuthenticatedPrincipal = null;
}
}