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

Commit b27ba8c

Browse files
authored
Merge pull request #387 from justcoding121/develop
Merge to beta
2 parents 553c89b + 2b9a7d3 commit b27ba8c

29 files changed

+295
-286
lines changed

Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ public void StartProxy()
6969
};
7070

7171
//Fired when a CONNECT request is received
72-
explicitEndPoint.BeforeTunnelConnect += OnBeforeTunnelConnect;
73-
74-
75-
explicitEndPoint.TunnelConnectRequest += OnTunnelConnectRequest;
76-
explicitEndPoint.TunnelConnectResponse += OnTunnelConnectResponse;
72+
explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest;
73+
explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse;
7774

7875
//An explicit endpoint is where the client knows about the existence of a proxy
7976
//So client sends request in a proxy friendly manner
@@ -111,9 +108,8 @@ public void StartProxy()
111108

112109
public void Stop()
113110
{
114-
explicitEndPoint.BeforeTunnelConnect -= OnBeforeTunnelConnect;
115-
explicitEndPoint.TunnelConnectRequest -= OnTunnelConnectRequest;
116-
explicitEndPoint.TunnelConnectResponse -= OnTunnelConnectResponse;
111+
explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest;
112+
explicitEndPoint.BeforeTunnelConnectResponse -= OnBeforeTunnelConnectResponse;
117113

118114
proxyServer.BeforeRequest -= OnRequest;
119115
proxyServer.BeforeResponse -= OnResponse;
@@ -126,27 +122,21 @@ public void Stop()
126122
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
127123
}
128124

129-
private async Task<bool> OnBeforeTunnelConnect(string hostname)
125+
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
130126
{
127+
string hostname = e.WebSession.Request.RequestUri.Host;
128+
Console.WriteLine("Tunnel to: " + hostname);
129+
131130
if (hostname.Contains("dropbox.com"))
132131
{
133132
//Exclude Https addresses you don't want to proxy
134133
//Useful for clients that use certificate pinning
135134
//for example dropbox.com
136-
return await Task.FromResult(true);
137-
}
138-
else
139-
{
140-
return await Task.FromResult(false);
135+
e.Excluded = true;
141136
}
142137
}
143138

144-
private async Task OnTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
145-
{
146-
Console.WriteLine("Tunnel to: " + e.WebSession.Request.Host);
147-
}
148-
149-
private async Task OnTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
139+
private async Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
150140
{
151141
}
152142

Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public MainWindow()
102102

103103
proxyServer.BeforeRequest += ProxyServer_BeforeRequest;
104104
proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
105-
explicitEndPoint.TunnelConnectRequest += ProxyServer_TunnelConnectRequest;
106-
explicitEndPoint.TunnelConnectResponse += ProxyServer_TunnelConnectResponse;
105+
explicitEndPoint.BeforeTunnelConnectRequest += ProxyServer_BeforeTunnelConnectRequest;
106+
explicitEndPoint.BeforeTunnelConnectResponse += ProxyServer_BeforeTunnelConnectResponse;
107107
proxyServer.ClientConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ClientConnectionCount = proxyServer.ClientConnectionCount; }); };
108108
proxyServer.ServerConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ServerConnectionCount = proxyServer.ServerConnectionCount; }); };
109109
proxyServer.Start();
@@ -113,15 +113,21 @@ public MainWindow()
113113
InitializeComponent();
114114
}
115115

116-
private async Task ProxyServer_TunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
116+
private async Task ProxyServer_BeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
117117
{
118+
string hostname = e.WebSession.Request.RequestUri.Host;
119+
if (hostname.EndsWith("webex.com"))
120+
{
121+
e.Excluded = true;
122+
}
123+
118124
await Dispatcher.InvokeAsync(() =>
119125
{
120126
AddSession(e);
121127
});
122128
}
123129

124-
private async Task ProxyServer_TunnelConnectResponse(object sender, SessionEventArgs e)
130+
private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, SessionEventArgs e)
125131
{
126132
await Dispatcher.InvokeAsync(() =>
127133
{

Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<WarningLevel>4</WarningLevel>
5252
</PropertyGroup>
5353
<ItemGroup>
54-
<Reference Include="StreamExtended, Version=1.0.135.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
55-
<HintPath>..\..\packages\StreamExtended.1.0.135-beta\lib\net45\StreamExtended.dll</HintPath>
54+
<Reference Include="StreamExtended, Version=1.0.138.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
55+
<HintPath>..\..\packages\StreamExtended.1.0.138-beta\lib\net45\StreamExtended.dll</HintPath>
5656
</Reference>
5757
<Reference Include="System" />
5858
<Reference Include="System.Data" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="StreamExtended" version="1.0.135-beta" targetFramework="net45" />
3+
<package id="StreamExtended" version="1.0.138-beta" targetFramework="net45" />
44
</packages>

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,16 @@ Sample request and response event handlers
126126
private IDictionary<Guid, string> requestBodyHistory
127127
= new ConcurrentDictionary<Guid, string>();
128128

129-
private async Task<bool> OnBeforeTunnelConnect(string hostname)
129+
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
130130
{
131+
string hostname = e.WebSession.Request.RequestUri.Host;
132+
131133
if (hostname.Contains("dropbox.com"))
132134
{
133135
//Exclude Https addresses you don't want to proxy
134136
//Useful for clients that use certificate pinning
135137
//for example dropbox.com
136-
return await Task.FromResult(true);
137-
}
138-
else
139-
{
140-
return await Task.FromResult(false);
138+
e.Excluded = true;
141139
}
142140
}
143141

Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task Simple_BC_Create_Certificate_Test()
1919
{
2020
var tasks = new List<Task>();
2121

22-
var mgr = new CertificateManager(null, null, false, false, false, new Lazy<Action<Exception>>(() => (e =>
22+
var mgr = new CertificateManager(null, null, false, false, false, new Lazy<ExceptionHandler>(() => (e =>
2323
{
2424
//Console.WriteLine(e.ToString() + e.InnerException != null ? e.InnerException.ToString() : string.Empty);
2525
})).Value);
@@ -48,7 +48,7 @@ public async Task Simple_Create_Win_Certificate_Test()
4848
{
4949
var tasks = new List<Task>();
5050

51-
var mgr = new CertificateManager(null, null, false, false, false, new Lazy<Action<Exception>>(() => (e =>
51+
var mgr = new CertificateManager(null, null, false, false, false, new Lazy<ExceptionHandler>(() => (e =>
5252
{
5353
//Console.WriteLine(e.ToString() + e.InnerException != null ? e.InnerException.ToString() : string.Empty);
5454
})).Value);

Titanium.Web.Proxy/CertificateHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal bool ValidateServerCertificate(object sender, X509Certificate certifica
2929
};
3030

3131
//why is the sender null?
32-
ServerCertificateValidationCallback.InvokeParallel(this, args);
32+
ServerCertificateValidationCallback.InvokeAsync(this, args, exceptionFunc).Wait();
3333
return args.IsValid;
3434
}
3535

@@ -88,7 +88,7 @@ internal X509Certificate SelectClientCertificate(object sender, string targetHos
8888
};
8989

9090
//why is the sender null?
91-
ClientCertificateSelectionCallback.InvokeParallel(this, args);
91+
ClientCertificateSelectionCallback.InvokeAsync(this, args, exceptionFunc).Wait();
9292
return args.ClientCertificate;
9393
}
9494

Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SessionEventArgs : EventArgs, IDisposable
2929
/// </summary>
3030
private readonly int bufferSize;
3131

32-
private readonly Action<Exception> exceptionFunc;
32+
private readonly ExceptionHandler exceptionFunc;
3333

3434
/// <summary>
3535
/// Backing field for corresponding public property
@@ -105,7 +105,7 @@ public bool ReRequest
105105
/// </summary>
106106
internal SessionEventArgs(int bufferSize,
107107
ProxyEndPoint endPoint,
108-
Action<Exception> exceptionFunc)
108+
ExceptionHandler exceptionFunc)
109109
{
110110
this.bufferSize = bufferSize;
111111
this.exceptionFunc = exceptionFunc;

Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ namespace Titanium.Web.Proxy.EventArguments
66
{
77
public class TunnelConnectSessionEventArgs : SessionEventArgs
88
{
9-
public bool IsHttpsConnect { get; set; }
9+
public bool Excluded { get; set; }
1010

11-
internal TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ConnectRequest connectRequest, Action<Exception> exceptionFunc)
11+
public bool IsHttpsConnect { get; internal set; }
12+
13+
internal TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ConnectRequest connectRequest, ExceptionHandler exceptionFunc)
1214
: base(bufferSize, endPoint, exceptionFunc)
1315
{
1416
WebSession.Request = connectRequest;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System;
2+
3+
namespace Titanium.Web.Proxy
4+
{
5+
public delegate void ExceptionHandler(Exception exception);
6+
}

0 commit comments

Comments
 (0)