-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterMiddleWare.cs
38 lines (33 loc) · 995 Bytes
/
CounterMiddleWare.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Owin.Types;
namespace Owin101.HelperAssemblies
{
using AppFunc = Func<IDictionary<string, object>, Task>;
public class CounterMiddleWare
{
private readonly AppFunc _next;
private int _count = 0;
public CounterMiddleWare(Func<IDictionary<string, object>, Task> next)
{
_next = next;
}
public async Task Invoke(IDictionary<string, object> env)
{
Interlocked.Increment(ref _count);
this._next(env);
var responseStream = env[OwinConstants.ResponseBody];
using (var s = (Stream)responseStream)
using (var sr = new StreamWriter(s))
{
await sr.WriteLineAsync("Called this page" + this._count + " times");
}
}
}
}