Skip to content

Commit

Permalink
Rider -> Cleanup http server code
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Jun 27, 2024
1 parent ae199f0 commit 0db4105
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/http/partials/Server/HTTP.MiddlewareDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MiddlewareDescriptor(string path, bool useParams,

public void Execute(IHTTP.ServerRequest request, IHTTP.ServerResponse response)
{
if(Next == null) return;
if (Next == null) return;
Next?.Callback(request, response, () => Next?.Execute(request, response));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/http/partials/Server/HTTP.ServerRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal ServerRequest(HttpResponseMessage message)
Encoding = GetEncodingFromHeader();

var buffer = message.Content.ReadAsByteArrayAsync().Result;

Body = new Body(buffer, Encoding, Headers);
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ private void SetQueriesFromUri(Uri uri)

foreach (var queryName in queryBuilder.AllKeys) Queries.Add(queryName, queryBuilder[queryName]);
}

private Encoding GetEncodingFromHeader()
{
var comparisonType = StringComparison.InvariantCultureIgnoreCase;
Expand Down
16 changes: 8 additions & 8 deletions src/http/partials/Server/HTTP.ServerTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void AcceptCallback(IAsyncResult result)
{
if (IsOpened)
{
HttpListenerContext context = _listener.EndGetContext(result);
var context = _listener.EndGetContext(result);

Task.Run(async () =>
{
Expand Down Expand Up @@ -192,17 +192,19 @@ private static string DefaultHtmlBody(string content)
private async Task HandleConnection(HttpListenerContext context)
{
var request = new ServerRequest(context.Request);

var response = new ServerResponse(context.Response);

var notFoundMessage = DefaultHtmlBody($"[{request.Method.Method.ToUpper()}] {request.Path}");

var middlewares = _server.MyMiddleware.Middlewares.ToList();
Console.WriteLine("Middleware found: " + middlewares.Count);

if (middlewares.Count > 0)
{
var descriptors = middlewares.FindAll(x =>
{
// allow global middleware
if (x.Path == HTTP.Middleware.GlobalPath) return true;
if (x.Path == Middleware.GlobalPath) return true;

if (!x.UseParams)
// simple path compare
Expand Down Expand Up @@ -232,11 +234,9 @@ private async Task HandleConnection(HttpListenerContext context)

if (descriptors.Count > 0)
{
Console.WriteLine("Middleware des found: " + descriptors.Count);

int count = descriptors.Count;
var count = descriptors.Count;

for (int i = 0; i < count; i++)
for (var i = 0; i < count; i++)
{
var descriptor = descriptors[i];

Expand Down Expand Up @@ -268,7 +268,7 @@ private async Task HandleConnection(HttpListenerContext context)
{
// handle all method
var handleMethod =
string.Equals(x.Method, HTTP.Map.ALL_MEHOD, StringComparison.CurrentCultureIgnoreCase)
string.Equals(x.Method, Map.ALL_MEHOD, StringComparison.CurrentCultureIgnoreCase)
||
string.Equals(request.Method.Method, x.Method,
StringComparison.CurrentCultureIgnoreCase);
Expand Down

0 comments on commit 0db4105

Please sign in to comment.