Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Mar 20, 2024
1 parent 69866e6 commit 5666911
Show file tree
Hide file tree
Showing 11 changed files with 640 additions and 80 deletions.
425 changes: 425 additions & 0 deletions src/Ext/CircularBuffer.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/Http/Hosting/HttpServerHostContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,19 @@ public void UseAutoScan<TModule>(Assembly t, bool activateInstances = true) wher
{
_context.HttpServer.RegisterHandler<THandler>();
}

/// <summary>
/// This method is an shortcut for calling <see cref="HttpServer.RegisterHandler"/>.
/// </summary>
/// <param name="handler">The instance of the server handler.</param>
/// <definition>
/// public void UseHandler(HttpServerHandler handler)
/// </definition>
/// <type>
/// Method
/// </type>
public void UseHandler(HttpServerHandler handler)
{
_context.HttpServer.RegisterHandler(handler);
}
}
43 changes: 40 additions & 3 deletions src/Http/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,33 @@ namespace Sisk.Core.Http
/// </type>
public partial class HttpServer : IDisposable
{
/// <summary>
/// Gets the X-Powered-By Sisk header value.
/// </summary>
/// <definition>
/// public static string PoweredBy { get; }
/// </definition>
/// <type>
/// Static property
/// </type>
public static string PoweredBy { get; private set; } = "";

/// <summary>
/// Gets the current Sisk version.
/// </summary>
/// <definition>
/// public static Version SiskVersion { get; }
/// </definition>
/// <type>
/// Static property
/// </type>
public static Version SiskVersion { get; private set; } = null!;

private bool _isListening = false;
private bool _isDisposing = false;
private HttpListener httpListener = new HttpListener();
private AsyncCallback _listenerCallback;
private ListeningHost? _onlyListeningHost;
internal static string poweredByHeader = "";
internal HttpEventSourceCollection _eventCollection = new HttpEventSourceCollection();
internal HttpWebSocketConnectionCollection _wsCollection = new HttpWebSocketConnectionCollection();
internal List<string>? listeningPrefixes;
Expand All @@ -41,7 +62,8 @@ public partial class HttpServer : IDisposable
static HttpServer()
{
Version assVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!;
poweredByHeader = $"Sisk/{assVersion.Major}.{assVersion.Minor}";
PoweredBy = $"Sisk/{assVersion.Major}.{assVersion.Minor}";
SiskVersion = assVersion;
}

/// <summary>
Expand Down Expand Up @@ -219,7 +241,7 @@ out Router router
/// <type>
/// Method
/// </type>
public string GetVersion() => poweredByHeader;
public string GetVersion() => PoweredBy;

/// <summary>
/// Creates a new default configuration <see cref="Sisk.Core.Http.HttpServer"/> instance with the given Route and server configuration.
Expand Down Expand Up @@ -253,6 +275,21 @@ public HttpServer(HttpServerConfiguration configuration)
handler.RegisterHandler(new T());
}

/// <summary>
/// Associate an <see cref="HttpServerHandler"/> in this HttpServer to handle functions such as requests, routers and contexts.
/// </summary>
/// <param name="obj">The instance of the server handler.</param>
/// <definition>
/// public void RegisterHandler(HttpServerHandler obj)
/// </definition>
/// <type>
/// Method
/// </type>
public void RegisterHandler(HttpServerHandler obj)
{
handler.RegisterHandler(obj);
}

/// <summary>
/// Restarts this HTTP server, sending all processing responses and starting them again, reading the listening ports again.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HttpServer__Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private async Task ProcessRequest(HttpListenerContext context)
if (ServerConfiguration.IncludeRequestIdHeader)
baseResponse.Headers.Set(flag.HeaderNameRequestId, request.RequestId.ToString());
if (flag.SendSiskHeader)
baseResponse.Headers.Set(HttpKnownHeaderNames.XPoweredBy, poweredByHeader);
baseResponse.Headers.Set(HttpKnownHeaderNames.XPoweredBy, PoweredBy);

long requestMaxSize = ServerConfiguration.MaximumContentLength;
if (requestMaxSize > 0 && baseRequest.ContentLength64 > requestMaxSize)
Expand Down
Loading

0 comments on commit 5666911

Please sign in to comment.