private static void Main(string[] args) { s_blockPageBytes = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BlockedPage.html")); // Let the user decide when to quit with ctrl+c. var manualResetEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, e) => { e.Cancel = true; manualResetEvent.Set(); Console.WriteLine("Shutting Down"); }; // Hooking into these properties gives us an abstract interface where we may // use informational, warning and error messages generated by the internals of // the proxy in whatsoever way we see fit, though the design was to allow users // to choose logging mechanisms. LoggerProxy.Default.OnInfo += (msg) => { Console.WriteLine("INFO: {0}", msg); }; LoggerProxy.Default.OnWarning += (msg) => { Console.WriteLine("WARN: {0}", msg); }; LoggerProxy.Default.OnError += (msg) => { Console.WriteLine("ERRO: {0}", msg); }; // Just create the server. var proxyServer = new WindowsProxyServer("Fake Authority", OnFirewallCheck, OnMsgBegin, OnMsgEnd); // Give it a kick. proxyServer.Start(); // And you're up and running. Console.WriteLine("Proxy Running"); Console.WriteLine("Listening for IPv4 HTTP connections on port {0}.", proxyServer.V4HttpEndpoint.Port); Console.WriteLine("Listening for IPv4 HTTPS connections on port {0}.", proxyServer.V4HttpsEndpoint.Port); Console.WriteLine("Listening for IPv6 HTTP connections on port {0}.", proxyServer.V6HttpEndpoint.Port); Console.WriteLine("Listening for IPv6 HTTPS connections on port {0}.", proxyServer.V6HttpsEndpoint.Port); // Don't exit on me yet fam. manualResetEvent.WaitOne(); Console.WriteLine("Exiting."); // Stop if you must. proxyServer.Stop(); }
private static void Main(string[] args) { GrantSelfFirewallAccess(); s_blockPageBytes = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BlockedPage.html")); // Let the user decide when to quit with ctrl+c. var manualResetEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, e) => { e.Cancel = true; manualResetEvent.Set(); Console.WriteLine("Shutting Down"); }; // Hooking into these properties gives us an abstract interface where we may use // informational, warning and error messages generated by the internals of the proxy in // whatsoever way we see fit, though the design was to allow users to choose logging mechanisms. LoggerProxy.Default.OnInfo += (msg) => { Console.WriteLine("INFO: {0}", msg); }; LoggerProxy.Default.OnWarning += (msg) => { Console.WriteLine("WARN: {0}", msg); }; LoggerProxy.Default.OnError += (msg) => { Console.WriteLine("ERRO: {0}", msg); }; var cfg = new ProxyServerConfiguration { AuthorityName = "Fake Authority", FirewallCheckCallback = OnFirewallCheck, HttpMessageReplayInspectionCallback = OnReplayInspection, NewHttpMessageHandler = OnNewMessage, HttpMessageWholeBodyInspectionHandler = OnWholeBodyContentInspection, HttpMessageStreamedInspectionHandler = OnStreamedContentInspection, HttpExternalRequestHandlerCallback = OnManualFulfillmentCallback, BlockExternalProxies = true }; // Just create the server. var proxyServer = new WindowsProxyServer(cfg); // Give it a kick. proxyServer.Start(0); // And you're up and running. Console.WriteLine("Proxy Running"); Console.WriteLine("Listening for IPv4 HTTP/HTTPS connections on port {0}.", proxyServer.V4HttpEndpoint.Port); Console.WriteLine("Listening for IPv6 HTTP/HTTPS connections on port {0}.", proxyServer.V6HttpEndpoint.Port); // Don't exit on me yet fam. manualResetEvent.WaitOne(); Console.WriteLine("Exiting."); // Stop if you must. proxyServer.Stop(); }