Skip to content

Commit c07cf97

Browse files
committed
Fix Middleware
1 parent d5a369c commit c07cf97

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Unosquare.Labs.EmbedIO/Middleware.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Unosquare.Labs.EmbedIO
22
{
33
using System.Net;
4+
using System.Threading.Tasks;
45

56
/// <summary>
67
/// Represents a Middleware abstract class
@@ -11,7 +12,7 @@ public abstract class Middleware
1112
/// Invokes the Middleware with a context
1213
/// </summary>
1314
/// <param name="context">The Middleware context</param>
14-
public abstract void Invoke(MiddlewareContext context);
15+
public abstract Task Invoke(MiddlewareContext context);
1516
}
1617

1718
/// <summary>
@@ -46,4 +47,4 @@ public MiddlewareContext(HttpListenerContext httpListenerContext, WebServer webs
4647
WebServer = webserver;
4748
}
4849
}
49-
}
50+
}

Unosquare.Labs.EmbedIO/WebServer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Unosquare.Labs.EmbedIO
1+
using System.Globalization;
2+
3+
namespace Unosquare.Labs.EmbedIO
24
{
35
using System;
46
using System.Collections.Generic;
@@ -240,7 +242,7 @@ public void UnregisterModule(Type moduleType)
240242
/// </summary>
241243
/// <param name="context">The context.</param>
242244
/// <param name="app"></param>
243-
private void HandleClientRequest(HttpListenerContext context, Middleware app)
245+
private async void HandleClientRequest(HttpListenerContext context, Middleware app)
244246
{
245247
// start with an empty request ID
246248
var requestId = "(not set)";
@@ -251,15 +253,15 @@ private void HandleClientRequest(HttpListenerContext context, Middleware app)
251253
if (app != null)
252254
{
253255
var middlewareContext = new MiddlewareContext(context, this);
254-
app.Invoke(middlewareContext);
256+
await app.Invoke(middlewareContext);
255257

256258
if (middlewareContext.Handled) return;
257259
}
258260

259261
// Create a request endpoint string
260262
var requestEndpoint = string.Join(":",
261263
context.Request.RemoteEndPoint.Address.ToString(),
262-
context.Request.RemoteEndPoint.Port.ToString());
264+
context.Request.RemoteEndPoint.Port.ToString(CultureInfo.InvariantCulture));
263265

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

0 commit comments

Comments
 (0)