|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Net; |
2 | 4 | using System.Text.RegularExpressions;
|
3 | 5 | using Titanium.Web.Proxy.EventArguments;
|
| 6 | +using Titanium.Web.Proxy.Models; |
4 | 7 |
|
5 | 8 | namespace Titanium.Web.Proxy.Test
|
6 | 9 | {
|
7 | 10 | public class ProxyTestController
|
8 | 11 | {
|
9 |
| - public int ListeningPort { get; set; } |
10 |
| - public bool EnableSsl { get; set; } |
11 |
| - public bool SetAsSystemProxy { get; set; } |
| 12 | + |
12 | 13 |
|
13 | 14 | public void StartProxy()
|
14 | 15 | {
|
15 | 16 | ProxyServer.BeforeRequest += OnRequest;
|
16 | 17 | ProxyServer.BeforeResponse += OnResponse;
|
17 | 18 |
|
18 |
| - ProxyServer.EnableSsl = EnableSsl; |
19 |
| - |
20 |
| - ProxyServer.SetAsSystemProxy = SetAsSystemProxy; |
21 |
| - |
22 | 19 | //Exclude Https addresses you don't want to proxy
|
23 | 20 | //Usefull for clients that use certificate pinning
|
24 | 21 | //for example dropbox.com
|
25 |
| - ProxyServer.ExcludedHttpsHostNameRegex.Add(".dropbox.com"); |
| 22 | + var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Loopback, 8000, true){ |
| 23 | + ExcludedHostNameRegex = new List<string>() { "dropbox.com" } |
| 24 | + }; |
26 | 25 |
|
| 26 | + var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Loopback, 8001, true); |
| 27 | + |
| 28 | + ProxyServer.AddEndPoint(explicitEndPoint); |
| 29 | + ProxyServer.AddEndPoint(transparentEndPoint); |
27 | 30 | ProxyServer.Start();
|
28 | 31 |
|
29 |
| - ProxyServer.ListeningPort = ProxyServer.ListeningPort; |
| 32 | + foreach (var endPoint in ProxyServer.ProxyEndPoints) |
| 33 | + Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ", endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port); |
| 34 | + |
| 35 | + ProxyServer.SetAsSystemProxy(explicitEndPoint); |
30 | 36 |
|
31 |
| - Console.WriteLine("Proxy listening on local machine port: {0} ", ProxyServer.ListeningPort); |
32 | 37 | }
|
33 | 38 |
|
34 | 39 | public void Stop()
|
|
0 commit comments