Skip to content

Commit

Permalink
Fix Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed May 19, 2015
1 parent d5a369c commit c07cf97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Unosquare.Labs.EmbedIO/Middleware.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Unosquare.Labs.EmbedIO
{
using System.Net;
using System.Threading.Tasks;

/// <summary>
/// Represents a Middleware abstract class
Expand All @@ -11,7 +12,7 @@ public abstract class Middleware
/// Invokes the Middleware with a context
/// </summary>
/// <param name="context">The Middleware context</param>
public abstract void Invoke(MiddlewareContext context);
public abstract Task Invoke(MiddlewareContext context);
}

/// <summary>
Expand Down Expand Up @@ -46,4 +47,4 @@ public MiddlewareContext(HttpListenerContext httpListenerContext, WebServer webs
WebServer = webserver;
}
}
}
}
10 changes: 6 additions & 4 deletions Unosquare.Labs.EmbedIO/WebServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Unosquare.Labs.EmbedIO
using System.Globalization;

namespace Unosquare.Labs.EmbedIO
{
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -240,7 +242,7 @@ public void UnregisterModule(Type moduleType)
/// </summary>
/// <param name="context">The context.</param>
/// <param name="app"></param>
private void HandleClientRequest(HttpListenerContext context, Middleware app)
private async void HandleClientRequest(HttpListenerContext context, Middleware app)
{
// start with an empty request ID
var requestId = "(not set)";
Expand All @@ -251,15 +253,15 @@ private void HandleClientRequest(HttpListenerContext context, Middleware app)
if (app != null)
{
var middlewareContext = new MiddlewareContext(context, this);
app.Invoke(middlewareContext);
await app.Invoke(middlewareContext);

if (middlewareContext.Handled) return;
}

// Create a request endpoint string
var requestEndpoint = string.Join(":",
context.Request.RemoteEndPoint.Address.ToString(),
context.Request.RemoteEndPoint.Port.ToString());
context.Request.RemoteEndPoint.Port.ToString(CultureInfo.InvariantCulture));

// Generate a random request ID. It's currently not important butit could be useful in the future.
requestId = string.Concat(DateTime.Now.Ticks.ToString(), requestEndpoint).GetHashCode().ToString("x2");
Expand Down

0 comments on commit c07cf97

Please sign in to comment.