Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit aeb9f31

Browse files
committed
Merge pull request #68 from justcoding121/release
Expect Continue Fixes
2 parents a4d42ab + e4c68b0 commit aeb9f31

30 files changed

+493
-367
lines changed

.build/default.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ Import-Module "$Here\Common" -DisableNameChecking
3131

3232
$NuGet = Join-Path $SolutionRoot ".nuget\nuget.exe"
3333

34-
$MSBuild ="${env:ProgramFiles(x86)}\MSBuild\12.0\Bin\msbuild.exe"
34+
$MSBuild ="${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\msbuild.exe"
3535

3636
FormatTaskName (("-"*25) + "[{0}]" + ("-"*25))
3737

3838
Task default -depends Clean, Build, Package
3939

4040
Task Build -depends Restore-Packages {
4141
exec { . $MSBuild $SolutionFile /t:Build /v:normal /p:Configuration=$Configuration }
42-
exec { . $MSBuild $SolutionFile /t:Build /v:normal /p:Configuration=$Configuration-Net45 }
4342
}
4443

4544
Task Package -depends Build {

Titanium.Web.Proxy.Test/App.config

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
1+
<?xml version="1.0" encoding="utf-8"?>
32
<configuration>
43
<startup>
5-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
65
</startup>
76
<runtime>
87
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
98
<dependentAssembly>
10-
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11-
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
9+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
10+
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0"/>
1211
</dependentAssembly>
1312
<dependentAssembly>
14-
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
15-
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
13+
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
14+
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0"/>
1615
</dependentAssembly>
1716
</assemblyBinding>
1817
</runtime>
1918

20-
</configuration>
19+
</configuration>

Titanium.Web.Proxy.Test/ProxyTestController.cs

+25-14
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace Titanium.Web.Proxy.Test
99
{
1010
public class ProxyTestController
1111
{
12-
13-
1412
public void StartProxy()
1513
{
1614
ProxyServer.BeforeRequest += OnRequest;
@@ -19,36 +17,35 @@ public void StartProxy()
1917
//Exclude Https addresses you don't want to proxy
2018
//Usefull for clients that use certificate pinning
2119
//for example dropbox.com
22-
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true){
23-
// ExcludedHttpsHostNameRegex = new List<string>() { "google.com", "dropbox.com" }
20+
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
21+
{
22+
// ExcludedHttpsHostNameRegex = new List<string>() { "google.com", "dropbox.com" }
2423
};
2524

2625
//An explicit endpoint is where the client knows about the existance of a proxy
2726
//So client sends request in a proxy friendly manner
2827
ProxyServer.AddEndPoint(explicitEndPoint);
2928
ProxyServer.Start();
3029

31-
30+
3231
//Transparent endpoint is usefull for reverse proxying (client is not aware of the existance of proxy)
3332
//A transparent endpoint usually requires a network router port forwarding HTTP(S) packets to this endpoint
3433
//Currently do not support Server Name Indication (It is not currently supported by SslStream class)
3534
//That means that the transparent endpoint will always provide the same Generic Certificate to all HTTPS requests
3635
//In this example only google.com will work for HTTPS requests
3736
//Other sites will receive a certificate mismatch warning on browser
3837
//Please read about it before asking questions!
39-
var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 8001, true) {
38+
var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 8001, true)
39+
{
4040
GenericCertificateName = "google.com"
41-
};
41+
};
4242
ProxyServer.AddEndPoint(transparentEndPoint);
43-
43+
4444

4545
foreach (var endPoint in ProxyServer.ProxyEndPoints)
46-
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
46+
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
4747
endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
4848

49-
//You can also add/remove end points after proxy has been started
50-
ProxyServer.RemoveEndPoint(transparentEndPoint);
51-
5249
//Only explicit proxies can be set as system proxy!
5350
ProxyServer.SetAsSystemHttpProxy(explicitEndPoint);
5451
ProxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
@@ -85,10 +82,20 @@ public void OnRequest(object sender, SessionEventArgs e)
8582

8683
//To cancel a request with a custom HTML content
8784
//Filter URL
88-
8985
if (e.ProxySession.Request.RequestUri.AbsoluteUri.Contains("google.com"))
9086
{
91-
e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
87+
e.Ok("<!DOCTYPE html>" +
88+
"<html><body><h1>" +
89+
"Website Blocked" +
90+
"</h1>" +
91+
"<p>Blocked by titanium web proxy.</p>" +
92+
"</body>" +
93+
"</html>");
94+
}
95+
//Redirect example
96+
if (e.ProxySession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org"))
97+
{
98+
e.Redirect("https://www.paypal.com");
9299
}
93100
}
94101

@@ -107,7 +114,11 @@ public void OnResponse(object sender, SessionEventArgs e)
107114
{
108115
if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
109116
{
117+
byte[] bodyBytes = e.GetResponseBody();
118+
e.SetResponseBody(bodyBytes);
119+
110120
string body = e.GetResponseBodyAsString();
121+
e.SetResponseBodyString(body);
111122
}
112123
}
113124
}

Titanium.Web.Proxy.Test/Titanium.Web.Proxy.Test.csproj

+8-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -11,49 +11,32 @@
1111
<RootNamespace>Titanium.Web.Proxy.Test</RootNamespace>
1212
<AssemblyName>Titanium.Web.Proxy.Test</AssemblyName>
1313
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
1718
<DebugType>full</DebugType>
1819
<Optimize>false</Optimize>
1920
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
2122
<ErrorReport>prompt</ErrorReport>
2223
<WarningLevel>4</WarningLevel>
23-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
24+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
25+
<Prefer32Bit>false</Prefer32Bit>
2426
</PropertyGroup>
2527
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2628
<DebugType>pdbonly</DebugType>
2729
<Optimize>true</Optimize>
2830
<OutputPath>bin\Release\</OutputPath>
29-
<DefineConstants>TRACE</DefineConstants>
31+
<DefineConstants>TRACE;NET45</DefineConstants>
3032
<ErrorReport>prompt</ErrorReport>
3133
<WarningLevel>4</WarningLevel>
32-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
34+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
35+
<Prefer32Bit>false</Prefer32Bit>
3336
</PropertyGroup>
3437
<PropertyGroup>
3538
<StartupObject />
3639
</PropertyGroup>
37-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug-Net45|AnyCPU'">
38-
<DebugSymbols>true</DebugSymbols>
39-
<OutputPath>bin\Debug-Net45\</OutputPath>
40-
<DefineConstants>DEBUG;TRACE</DefineConstants>
41-
<DebugType>full</DebugType>
42-
<PlatformTarget>AnyCPU</PlatformTarget>
43-
<ErrorReport>prompt</ErrorReport>
44-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
45-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
46-
</PropertyGroup>
47-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-Net45|AnyCPU'">
48-
<OutputPath>bin\Release-Net45\</OutputPath>
49-
<DefineConstants>TRACE</DefineConstants>
50-
<Optimize>true</Optimize>
51-
<DebugType>pdbonly</DebugType>
52-
<PlatformTarget>AnyCPU</PlatformTarget>
53-
<ErrorReport>prompt</ErrorReport>
54-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
55-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
56-
</PropertyGroup>
5740
<ItemGroup>
5841
<Reference Include="System" />
5942
<Reference Include="System.ComponentModel.DataAnnotations" />

Titanium.Web.Proxy.sln

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.31101.0
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25123.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B6DBABDC-C985-4872-9C38-B4E5079CBC4B}"
77
EndProject
@@ -19,27 +19,17 @@ EndProject
1919
Global
2020
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2121
Debug|Any CPU = Debug|Any CPU
22-
Debug-Net45|Any CPU = Debug-Net45|Any CPU
2322
Release|Any CPU = Release|Any CPU
24-
Release-Net45|Any CPU = Release-Net45|Any CPU
2523
EndGlobalSection
2624
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2725
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2826
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Debug|Any CPU.Build.0 = Debug|Any CPU
29-
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Debug-Net45|Any CPU.ActiveCfg = Debug-Net45|Any CPU
30-
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Debug-Net45|Any CPU.Build.0 = Debug-Net45|Any CPU
3127
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Release|Any CPU.ActiveCfg = Release|Any CPU
3228
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Release|Any CPU.Build.0 = Release|Any CPU
33-
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Release-Net45|Any CPU.ActiveCfg = Release-Net45|Any CPU
34-
{F3B7E553-1904-4E80-BDC7-212342B5C952}.Release-Net45|Any CPU.Build.0 = Release-Net45|Any CPU
3529
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3630
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Debug|Any CPU.Build.0 = Debug|Any CPU
37-
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Debug-Net45|Any CPU.ActiveCfg = Debug-Net45|Any CPU
38-
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Debug-Net45|Any CPU.Build.0 = Debug-Net45|Any CPU
3931
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Release|Any CPU.ActiveCfg = Release|Any CPU
4032
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Release|Any CPU.Build.0 = Release|Any CPU
41-
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Release-Net45|Any CPU.ActiveCfg = Release-Net45|Any CPU
42-
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}.Release-Net45|Any CPU.Build.0 = Release-Net45|Any CPU
4333
EndGlobalSection
4434
GlobalSection(SolutionProperties) = preSolution
4535
HideSolutionNode = FALSE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Titanium.Web.Proxy.Compression
2+
{
3+
class CompressionFactory
4+
{
5+
public ICompression Create(string type)
6+
{
7+
switch (type)
8+
{
9+
case "gzip":
10+
return new GZipCompression();
11+
case "deflate":
12+
return new DeflateCompression();
13+
case "zlib":
14+
return new ZlibCompression();
15+
default:
16+
return null;
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO;
2+
using System.IO.Compression;
3+
4+
namespace Titanium.Web.Proxy.Compression
5+
{
6+
class DeflateCompression : ICompression
7+
{
8+
public byte[] Compress(byte[] responseBody)
9+
{
10+
using (var ms = new MemoryStream())
11+
{
12+
using (var zip = new DeflateStream(ms, CompressionMode.Compress, true))
13+
{
14+
zip.Write(responseBody, 0, responseBody.Length);
15+
}
16+
17+
return ms.ToArray();
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Ionic.Zlib;
2+
using System.IO;
3+
4+
namespace Titanium.Web.Proxy.Compression
5+
{
6+
class GZipCompression : ICompression
7+
{
8+
public byte[] Compress(byte[] responseBody)
9+
{
10+
using (var ms = new MemoryStream())
11+
{
12+
using (var zip = new GZipStream(ms, CompressionMode.Compress, true))
13+
{
14+
zip.Write(responseBody, 0, responseBody.Length);
15+
}
16+
17+
return ms.ToArray();
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Titanium.Web.Proxy.Compression
2+
{
3+
interface ICompression
4+
{
5+
byte[] Compress(byte[] responseBody);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Ionic.Zlib;
2+
using System.IO;
3+
4+
namespace Titanium.Web.Proxy.Compression
5+
{
6+
class ZlibCompression : ICompression
7+
{
8+
public byte[] Compress(byte[] responseBody)
9+
{
10+
using (var ms = new MemoryStream())
11+
{
12+
using (var zip = new ZlibStream(ms, CompressionMode.Compress, true))
13+
{
14+
zip.Write(responseBody, 0, responseBody.Length);
15+
}
16+
17+
return ms.ToArray();
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Titanium.Web.Proxy.Decompression
2+
{
3+
class DecompressionFactory
4+
{
5+
public IDecompression Create(string type)
6+
{
7+
switch(type)
8+
{
9+
case "gzip":
10+
return new GZipDecompression();
11+
case "deflate":
12+
return new DeflateDecompression();
13+
case "zlib":
14+
return new ZlibDecompression();
15+
default:
16+
return new DefaultDecompression();
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Titanium.Web.Proxy.Decompression
2+
{
3+
class DefaultDecompression : IDecompression
4+
{
5+
public byte[] Decompress(byte[] compressedArray)
6+
{
7+
return compressedArray;
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Ionic.Zlib;
2+
using System.IO;
3+
4+
namespace Titanium.Web.Proxy.Decompression
5+
{
6+
class DeflateDecompression : IDecompression
7+
{
8+
public byte[] Decompress(byte[] compressedArray)
9+
{
10+
var stream = new MemoryStream(compressedArray);
11+
12+
using (var decompressor = new DeflateStream(stream, CompressionMode.Decompress))
13+
{
14+
var buffer = new byte[ProxyServer.BUFFER_SIZE];
15+
16+
using (var output = new MemoryStream())
17+
{
18+
int read;
19+
while ((read = decompressor.Read(buffer, 0, buffer.Length)) > 0)
20+
{
21+
output.Write(buffer, 0, read);
22+
}
23+
24+
return output.ToArray();
25+
}
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)