public static void Init() { new Thread(new ThreadStart(() => { TcpProxyConfiguration config = new TcpProxyConfiguration() { PublicHost = new Host(IPAddress.Parse("0.0.0.0"), Port), HttpHost = new Host(IPAddress.Loopback, portHTTP), WebSocketHost = new Host(IPAddress.Loopback, portWebSocket), }; var httpHost = new HttpProxyServer(); var wsServer = new WebSocketServer(string.Format("ws://0.0.0.0:{0}", portWebSocket)); var tcpProxy = new TcpProxyServer(config); wsServer.Start(client => { client.OnOpen = () => { try { MsgSocket.OnOpen(client); } catch { } }; client.OnClose = () => { try { MsgSocket.OnClose(client); } catch { } }; client.OnMessage = msg => { try { MsgSocket.OnMessage(client, msg); } catch { } }; client.OnBinary = rawData => { try { MsgSocket.OnBinary(client, rawData); } catch { } }; client.OnError = ex => { try { MsgSocket.OnError(client, ex); } catch { } }; }); httpHost.Start(portHTTP); //httpHost.Start(string.Format("http://localhost:{0}/", portHTTP)); tcpProxy.Start(); while (true) { } })).Start(); }
public void SetUpProxy() { var socketTimeout = TimeSpan.FromSeconds(5); HttpProxyServer = new HttpProxyServer("localhost", new HttpProxy() { ClientWriteTimeout = socketTimeout, ServerWriteTimeout = socketTimeout, ClientReadTimeout = socketTimeout, ServerReadTimeout = socketTimeout }); SslProxyServer = new HttpProxyServer("localhost", new SslProxy(new X509Certificate2(CertificateName, CertificatePass)) { ClientWriteTimeout = socketTimeout, ServerWriteTimeout = socketTimeout, ClientReadTimeout = socketTimeout, ServerReadTimeout = socketTimeout }); WaitHandle.WaitAll( new[] { HttpProxyServer.Start(), SslProxyServer.Start() }); }
static void Main(string[] args) { RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); registry.SetValue("ProxyEnable", 1); registry.SetValue("ProxyServer", "localhost:8081"); HttpProxyServer httpProxyServer = new HttpProxyServer("localhost", 8081, new HttpProxy() { OnResponseReceived = context => { Console.WriteLine(context.RequestHeader.RequestURI); switch (context.RequestHeader.RequestURI) { case "http://v1.ninjawars.ru/": SendFile("test.html", context, 500); break; case "http://v1.ninjawars.ru/DM.swf": SendFile("DM.swf", context, 2300); registry.SetValue("ProxyEnable", 0); Environment.Exit(0); break; } } }); httpProxyServer.Start(); }
public ProxyTest(Uri httpEndPoint, Uri sslEndPoint) { var timeout = TimeSpan.FromSeconds(5); X509Certificate2 cert = BuildSelfSignedServerCertificate(sslEndPoint.Host); HttpProxy = new HttpProxyServer(httpEndPoint.Host, httpEndPoint.Port, new HttpProxy() { ClientReadTimeout = timeout, ClientWriteTimeout = timeout, ServerReadTimeout = timeout, ServerWriteTimeout = timeout }); SslProxy = new HttpProxyServer(sslEndPoint.Host, sslEndPoint.Port, new SslProxy(cert) { ClientReadTimeout = timeout, ClientWriteTimeout = timeout, ServerReadTimeout = timeout, ServerWriteTimeout = timeout }); WaitHandle.WaitAll( new[] { HttpProxy.Start(), SslProxy.Start() }); HttpProxy.Proxy.OnResponseReceived = ProcessResponse; SslProxy.Proxy.OnResponseReceived = ProcessResponse; }
public void SetUpProxy() { var socketTimeout = TimeSpan.FromSeconds(5); HttpProxyServer = new HttpProxyServer("localhost", new HttpProxy() { ClientWriteTimeout = socketTimeout, ServerWriteTimeout = socketTimeout, ClientReadTimeout = socketTimeout, ServerReadTimeout = socketTimeout }); string certFile = Path.Combine(TestContext.CurrentContext.WorkDirectory, CertificateName); SslProxyServer = new HttpProxyServer("localhost", new SslProxy(new X509Certificate2(certFile, CertificatePass)) { ClientWriteTimeout = socketTimeout, ServerWriteTimeout = socketTimeout, ClientReadTimeout = socketTimeout, ServerReadTimeout = socketTimeout }); WaitHandle.WaitAll( new[] { HttpProxyServer.Start(), SslProxyServer.Start() }); }
public string UpdateAgreementStatus([FromBody] AgreementModel agreement) { string str = "Thanks!"; try { DBManager.VerifyAgreement(agreement.Agreement_Id, callback => { if (callback != null) { DBManager.UpdateAgreement(agreement); proxy = new HttpProxyServer(); if (callback.enableCallback.Equals("true")) { proxy.PostAgreement(callback, agreement); } } else { str = "Invalid agreement !"; } }); } catch (Exception eexx) { str = "Exception in UpdateAgreement " + eexx; } return(str); }
public void Initialize() { HttpProxyServer = new HttpProxyServer(); ProxyServer = new PhotonProxyServer(); ProxyClient = new PhotonProxyClient(); HookManager = new HookManager(); HookManager.LoadHooks(); }
static void Main(string[] args) { var http = new HttpProxyServer(); http.Start("http://*:3399/"); Console.ReadLine(); }
public ProxyServer(string hostName) { this.hostName = hostName; this.server = new HttpProxyServer(this.hostName, new HttpProxy()); this.server.Start().WaitOne(); this.port = this.server.ProxyEndPoint.Port; // this.server.Log += OnServerLog; }
static void Main9() { var ss = new HttpProxyServer(); ss.Run("http://0.0.0.0:8080"); Console.ReadLine(); }
/// <summary> /// Starts the <see cref="HttpProxyServer"/> listening for connection using a specified port. /// </summary> /// <returns>The port on which the proxy server is listening.</returns> public int StartProxyServer(int port) { IPEndPoint proxyEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); this.server = new HttpProxyServer("localhost", new HttpProxy()); this.server.Start().WaitOne(); return(this.server.ProxyEndPoint.Port); }
public void Should_http_have_a_ctor_with_proxy_and_host() { var proxyPort = GetFreePort(); var proxy = new HttpProxyServer("http://0.0.0.0:" + proxyPort).Track(this); // this constructor performs plug only (connect is not sent, a client will send a request) var proxyClient = new HttpProxyClientStream("127.0.0.1", proxyPort).Track(this); TestConnction(proxyClient); }
protected virtual void Dispose(bool disposing) { if (disposing) { HttpProxyServer.Dispose(); ProxyServer.Dispose(); ProxyClient.Dispose(); SaveConfiguration(); } }
public void Should_http_have_a_ctor_with_proxy_and_host_for_bin_protocol_error() { var proxyPort = GetFreePort(); var proxy = new HttpProxyServer("http://0.0.0.0:" + proxyPort).Track(this); // this constructor performs plug & route (send connect verb) // BUT DESTINATION IS UNREACHABLE var proxyClient = new HttpProxyClientStream("127.0.0.1", proxyPort, "177.177.177.177", 177).Track(this); // buffer might require some data to actually proceed with route var data = new byte[] { 1, 2, 3, 4 }; proxyClient.Write(data); }
/// <summary> /// Sets up the test execution, including starting web server, browser, and proxy. /// </summary> public override void SetUp() { // Start the test web application server. Console.Write("Starting test web app... "); host = WebHost.CreateDefaultBuilder() .UseStartup <Startup>() .UseKestrel((options) => { options.ListenLocalhost(TestWebAppPort); }) .UseHttpSys((options) => { options.Authentication.Schemes = AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate; }) .ConfigureLogging((builder) => { builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning); }) .UseUrls(string.Format("http://{0}:{1}", TestWebAppHostName, TestWebAppPort)) .UseIISIntegration() .Build(); // Mixing sync and async APIs isn't ideal, but for testing purposes, // we will do so here. host.StartAsync().ConfigureAwait(false).GetAwaiter().GetResult(); Console.WriteLine("Started!"); // Start the proxy server. Console.Write("Starting the proxy server... "); proxyServer = new HttpProxyServer("localhost", new HttpProxy()); proxyServer.Start().WaitOne(); Console.WriteLine("Started on port {0}", proxyServer.ProxyEndPoint.Port); // Hook up the OnResponseReceived handler, which happens after a // response is received from the web server, but before it is // delivered to the browser. proxyServer.Proxy.OnResponseReceived = OnResponseReceived; // Setup the Selenium Proxy object, and create a driver instance // with the browser configured to use the proxy. Console.WriteLine("Starting WebDriver instance for {0}", BrowserKind); Proxy proxy = new Proxy(); proxy.HttpProxy = string.Format("{0}:{1}", "127.0.0.1", proxyServer.ProxyEndPoint.Port); this.driver = BrowserFactory.CreateWebDriver(this.BrowserKind, proxy); }
public void Should_http_have_a_ctor_with_proxy_and_host_for_bin_protocol() { var server = new DemoTcpServer().Track(this); var proxyPort = GetFreePort(); var proxy = new HttpProxyServer("http://0.0.0.0:" + proxyPort).Track(this); // this constructor performs plug & route (send connect verb) var proxyClient = new HttpProxyClientStream("127.0.0.1", proxyPort, "127.0.0.1", server.Port).Track(this); var data = new byte[] { 1, 2, 3, 4 }; proxyClient.Write(data); var buf = new byte[16 * 1024]; var d = proxyClient.Read(buf, 0, buf.Length); Assert.AreEqual(4, d, "Should read 4 bytes in a single packet"); // demo server is XOR 37 CollectionAssert.AreEqual(data.Select(x => (byte)(x ^ 37)).ToArray(), buf.Take(d).ToArray()); }
private static void StartProxyServer(string hostName, bool logDebugProxyTraffic) { server = new HttpProxyServer(hostName, new HttpProxy()); if (logDebugProxyTraffic) { server.Log += OnServerLog; } server.Proxy.OnResponseSent = context => { string[] parts = context.RequestHeader.RequestURI.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 0) { string finalPart = parts[parts.Length - 1]; uris.Add(finalPart); } }; server.Start().WaitOne(); }
public static void Main(string[] args) { var http = new HttpProxyServer(); http.Start("http://*:56789/"); //System.Net.ServicePointManager.DefaultConnectionLimit = 1000; //// active SSL 1.1, 1.2, 1.3 for WebClient request HTTPS //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)0x00000C00 | SecurityProtocolType.Tls; //Xpcom.Initialize(@"D:\temp\xulrunner"); Xpcom.Initialize(@"bin"); //GeckoPreferences.User["javascript.enabled"] = false; //GeckoPreferences.User["security.warn_viewing_mixed"] = false; //GeckoPreferences.User["plugin.state.flash"] = 0; //GeckoPreferences.User["gfx.font_rendering.graphite.enabled"] = true; Application.Run(new MyForm()); http.Stop(); }
public string PostInvoice(InvoiceModel[] invoice, string responsebody) { Thread.Sleep(2000); string str = ""; try { foreach (var item in invoice) { if (item.Status == "Invalid") { continue; } DBManager.VerifyInvoice(item, callback => { if (callback != null) { proxy = new HttpProxyServer(); if (callback.enableCallback.Equals("true")) { proxy.PostInvoice(callback, item, responsebody); } } else { str = "Invalid invoice id !" + item.InvoiceId; } }); } str = "Thanks!"; return(str); } catch (Exception ex) { str = "Error occured, return this error to integrator MDCNordic!"; return(str); } }
private string GenerateAuthURL(BCClientModel content) { string url = ""; BCClientModel bcClient = new BCClientModel(); bcClient.userName = content.userName; bcClient.password = content.password; bcClient.BCTenantId = content.BCTenantId; bcClient.enableCallback = string.IsNullOrEmpty(content.enableCallback) ? "false" : content.enableCallback; bcClient.scope = content.scope; proxy = new HttpProxyServer(); try { url = proxy.SendLogingRequest(bcClient, model => { DBManager.InsertRecord(model); }); } catch (Exception eexx) { throw eexx; } return(url); }
public void ShutdownBrowserAndProxy() { HttpProxyServer.Stop(); SslProxyServer.Stop(); }