-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleAnalyticsFilterStream.cs
More file actions
executable file
·40 lines (35 loc) · 1.21 KB
/
GoogleAnalyticsFilterStream.cs
File metadata and controls
executable file
·40 lines (35 loc) · 1.21 KB
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
39
40
using System;
using System.IO;
using System.Text;
using System.Web;
namespace GoogleAnalyticsModule
{
public class GoogleAnalyticsFilterStream : MemoryStream
{
private readonly Stream originalStream;
private readonly Encoding encoding;
private readonly GoogleAnalyticsFilterStream.FilterReplacementDelegate filterReplacementDelegate;
public GoogleAnalyticsFilterStream(Stream originalStream, GoogleAnalyticsFilterStream.FilterReplacementDelegate replacementFunction, Encoding encoding)
{
this.originalStream = originalStream;
this.filterReplacementDelegate = replacementFunction;
this.encoding = encoding;
}
public override void Write(byte[] buffer, int offset, int count)
{
if (HttpContext.Current.Response.ContentType.Contains("html"))
{
string str = this.encoding.GetString(buffer, offset, count);
bool flag = false;
string str1 = this.filterReplacementDelegate(str, out flag);
if (flag)
{
this.originalStream.Write(this.encoding.GetBytes(str1), 0, this.encoding.GetByteCount(str1));
return;
}
}
this.originalStream.Write(buffer, offset, count);
}
public delegate string FilterReplacementDelegate(string originalStreamString, out bool modified);
}
}