Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Aug 13, 2024
1 parent f55f542 commit f3c1806
Show file tree
Hide file tree
Showing 19 changed files with 802 additions and 200 deletions.
2 changes: 1 addition & 1 deletion src/Entity/HttpHeaderCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection.PortableExecutable;
using System.Text;
using Header = Sisk.Core.Internal.HttpKnownHeaderNames;
using Header = Sisk.Core.Http.HttpKnownHeaderNames;

namespace Sisk.Core.Entity;

Expand Down
1 change: 1 addition & 0 deletions src/Entity/MultipartFormReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// File name: MultipartFormReader.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Http;
using Sisk.Core.Internal;
using System;
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion src/Entity/MultipartObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Http;
using Sisk.Core.Internal;
using System.Collections.Specialized;
using System.Text;

Expand Down
1 change: 0 additions & 1 deletion src/Http/CookieHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// File name: CookieHelpers.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Internal;
using System.Web;

namespace Sisk.Core.Http;
Expand Down
134 changes: 134 additions & 0 deletions src/Http/Handlers/AsyncHttpServerHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// The Sisk Framework source code
// Copyright (c) 2023 PROJECT PRINCIPIUM
//
// The code below is licensed under the MIT license as
// of the date of its publication, available at
//
// File name: AsyncHttpServerHandler.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Entity;
using Sisk.Core.Routing;

namespace Sisk.Core.Http.Handlers;

/// <summary>
/// Represents an asynchronous event handler for the <see cref="HttpServer"/>, router, and related events.
/// </summary>
public abstract class AsyncHttpServerHandler : HttpServerHandler
{
/// <summary>
/// Method that is called immediately before starting the <see cref="HttpServer"/>.
/// </summary>
/// <param name="server">The HTTP server entity which is starting.</param>
protected virtual Task OnServerStartingAsync(HttpServer server) => Task.CompletedTask;

/// <summary>
/// Method that is called immediately after starting the <see cref="HttpServer"/>, when it's
/// ready and listening.
/// </summary>
/// <param name="server">The HTTP server entity which is ready.</param>
protected virtual Task OnServerStartedAsync(HttpServer server) => Task.CompletedTask;

/// <summary>
/// Method that is called before the <see cref="HttpServer"/> stop, when it is
/// stopping from listening requests.
/// </summary>
/// <param name="server">The HTTP server entity which is stopping.</param>
protected virtual Task OnServerStoppingAsync(HttpServer server) => Task.CompletedTask;

/// <summary>
/// Method that is called after the <see cref="HttpServer"/> is stopped, meaning
/// it has stopped from listening to requests.
/// </summary>
/// <param name="server">The HTTP server entity which has stopped.</param>
protected virtual Task OnServerStoppedAsync(HttpServer server) => Task.CompletedTask;

/// <summary>
/// Method that is called when an <see cref="Router"/> is binded to the HTTP server.
/// </summary>
/// <param name="router">The router entity which is binded.</param>
protected virtual Task OnSetupRouterAsync(Router router) => Task.CompletedTask;

/// <summary>
/// Method that is called when an HTTP context is created within an
/// <see cref="HttpRequest"/> object.
/// </summary>
/// <param name="contextBag">The creating context bag.</param>
protected virtual Task OnContextBagCreatedAsync(TypedValueDictionary contextBag) => Task.CompletedTask;

/// <summary>
/// Method that is called when an <see cref="HttpRequest"/> is received in the
/// HTTP server.
/// </summary>
/// <param name="request">The connecting HTTP request entity.</param>
protected virtual Task OnHttpRequestOpenAsync(HttpRequest request) => Task.CompletedTask;

/// <summary>
/// Method that is called when an <see cref="HttpRequest"/> is closed in the
/// HTTP server.
/// </summary>
/// <param name="result">The result of the execution of the request.</param>
protected virtual Task OnHttpRequestCloseAsync(HttpServerExecutionResult result) => Task.CompletedTask;

/// <summary>
/// Method that is called when an exception is caught in the HTTP server. This method is called
/// regardless of whether <see cref="HttpServerConfiguration.ThrowExceptions"/> is enabled or not.
/// </summary>
/// <param name="exception">The exception object.</param>
protected virtual Task OnExceptionAsync(Exception exception) => Task.CompletedTask;

/// <inheritdoc/>
protected sealed override void OnContextBagCreated(TypedValueDictionary contextBag)
{
OnContextBagCreatedAsync(contextBag).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnException(Exception exception)
{
OnExceptionAsync(exception).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnHttpRequestClose(HttpServerExecutionResult result)
{
OnHttpRequestCloseAsync(result).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnHttpRequestOpen(HttpRequest request)
{
OnHttpRequestOpenAsync(request).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnServerStarted(HttpServer server)
{
OnServerStartedAsync(server).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnServerStarting(HttpServer server)
{
OnServerStartingAsync(server).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnServerStopped(HttpServer server)
{
OnServerStoppedAsync(server).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnServerStopping(HttpServer server)
{
OnServerStoppingAsync(server).GetAwaiter().GetResult();
}

/// <inheritdoc/>
protected sealed override void OnSetupRouter(Router router)
{
OnSetupRouterAsync(router).GetAwaiter().GetResult();
}
}
8 changes: 4 additions & 4 deletions src/Http/Handlers/HttpServerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// File name: HttpServerHandler.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Entity;
using Sisk.Core.Routing;

namespace Sisk.Core.Http.Handlers;
Expand Down Expand Up @@ -52,16 +53,15 @@ protected virtual void OnServerStopped(HttpServer server) { }
/// </summary>
/// <param name="router">The router entity which is binded.</param>
protected virtual void OnSetupRouter(Router router) { }

internal void InvokeOnSetupRouter(Router router) => OnSetupRouter(router);

/// <summary>
/// Method that is called when an <see cref="HttpContextBagRepository"/> is created within an
/// Method that is called when an HTTP context is created within an
/// <see cref="HttpRequest"/> object.
/// </summary>
/// <param name="contextBag">The creating context bag.</param>
protected virtual void OnContextBagCreated(HttpContextBagRepository contextBag) { }
internal void InvokeOnContextBagCreated(HttpContextBagRepository contextBag) => OnContextBagCreated(contextBag);
protected virtual void OnContextBagCreated(TypedValueDictionary contextBag) { }
internal void InvokeOnContextBagCreated(TypedValueDictionary contextBag) => OnContextBagCreated(contextBag);

/// <summary>
/// Method that is called when an <see cref="HttpRequest"/> is received in the
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Handlers/HttpServerHandlerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// File name: HttpServerHandlerRepository.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Entity;
using Sisk.Core.Routing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -56,7 +57,7 @@ private void CallEvery(Action<HttpServerHandler> action)
internal void ServerStarting(HttpServer val) => CallEvery(handler => handler.InvokeOnServerStarting(val));
internal void ServerStarted(HttpServer val) => CallEvery(handler => handler.InvokeOnServerStarted(val));
internal void SetupRouter(Router val) => CallEvery(handler => handler.InvokeOnSetupRouter(val));
internal void ContextBagCreated(HttpContextBagRepository val) => CallEvery(handler => handler.InvokeOnContextBagCreated(val));
internal void ContextBagCreated(TypedValueDictionary val) => CallEvery(handler => handler.InvokeOnContextBagCreated(val));
internal void HttpRequestOpen(HttpRequest val) => CallEvery(handler => handler.InvokeOnHttpRequestOpen(val));
internal void HttpRequestClose(HttpServerExecutionResult val) => CallEvery(handler => handler.InvokeOnHttpRequestClose(val));
internal void Exception(Exception val) => CallEvery(handler => handler.InvokeOnException(val));
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class HttpContext
/// <summary>
/// Gets or sets a managed object that is accessed and modified by request handlers.
/// </summary>
public HttpContextBagRepository RequestBag { get; set; } = new HttpContextBagRepository();
public TypedValueDictionary RequestBag { get; set; } = new TypedValueDictionary();

/// <summary>
/// Gets the context HTTP Server instance.
Expand Down
19 changes: 0 additions & 19 deletions src/Http/HttpContextBagRepository.cs

This file was deleted.

Loading

0 comments on commit f3c1806

Please sign in to comment.