示例#1
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="configuration">
        /// The shared, proxy configuration.
        /// </param>
        /// <param name="replayFactory">
        /// A shared, non-owning instance of the replay factory we'll let our HTTP handlers create
        /// replays with, if requested by the user.
        /// </param>
        internal FilterResponseHandlerFactory(ProxyServerConfiguration configuration, ReplayResponseHandlerFactory replayFactory)
        {
            _configuration = configuration;

            _replayFactory = replayFactory;

            if (replayFactory == null)
            {
                throw new ArgumentException("The replay factor must be defined.", nameof(replayFactory));
            }

            // We need UseCookies set to false here. We then need to set per-request cookies by
            // manually adding the "Cookie" header. If we don't have UseCookies set to false here,
            // this will not work.
            //
            // Of course, if the user wants to manage this, then we just use their handler.
            if (configuration.CustomProxyHandler == null)
            {
                configuration.CustomProxyHandler = new HttpClientHandler
                {
                    AutomaticDecompression   = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                    UseCookies               = false,
                    ClientCertificateOptions = ClientCertificateOption.Automatic,
                    AllowAutoRedirect        = false,
                    Proxy = null
                };
            }

            _client = new HttpClient(configuration.CustomProxyHandler, true);
        }
 /// <summary>
 /// Constructs a FilterHttpResponseHandler instance.
 /// </summary>
 /// <param name="client">
 /// The HttpClient instance to use.
 /// </param>
 /// <param name="replayFactory">
 /// The replay factory to use for creating new replay instances as requested.
 /// </param>
 /// <param name="configuration">
 /// The shared, proxy configuration.
 /// </param>
 /// <exception cref="ArgumentException">
 /// If the supplied configuration is null or invalid, this constructor will throw.
 /// </exception>
 public FilterHttpResponseHandler(
     HttpClient client,
     ReplayResponseHandlerFactory replayFactory,
     ProxyServerConfiguration configuration
     ) : base(configuration)
 {
     _client        = client;
     _replayFactory = replayFactory;
 }
        /// <summary>
        /// Constructs a AbstractFilterResponseHandler instance.
        /// </summary>
        /// <param name="configuration">
        /// The shared, proxy configuration.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the supplied configuration is null or invalid, this constructor will throw.
        /// </exception>
        public AbstractFilterResponseHandler(
            ProxyServerConfiguration configuration
            )
        {
            _configuration = configuration;

            if (_configuration == null || !_configuration.IsValid)
            {
                throw new ArgumentException("Configuration is null or invalid. Ensure it is defined, and that all callbacks are defined.");
            }
        }
        /// <summary>
        /// saves the proxy server settings from the registry
        /// </summary>
        private void SaveSettings()
        {
            var proxyServerConfiguration = new ProxyServerConfiguration
            {
                Address  = this.Address,
                Port     = this.Port,
                UserName = this.UserName,
                Password = this.Password
            };

            ProxyServerConfigurationManager.Write(proxyServerConfiguration);
        }
示例#5
0
        public void SetUp()
        {
            try
            {
                Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\RHEA\CDP4\ProxyServerConfiguration");
            }
            catch (Exception e)
            {
            }

            this.proxyServerConfiguration = new ProxyServerConfiguration()
            {
                Address  = "proxy.proxy.com",
                Port     = "8080",
                UserName = "******",
                Password = "******"
            };
        }
示例#6
0
 /// <summary>
 /// Constructs a FilterWebsocketHandler instance.
 /// </summary>
 /// <param name="configuration">
 /// The shared, proxy configuration.
 /// </param>
 /// <exception cref="ArgumentException">
 /// If the supplied configuration is null or invalid, this constructor will throw.
 /// </exception>
 public FilterWebsocketHandler(
     ProxyServerConfiguration configuration
     ) : base(configuration)
 {
 }
示例#7
0
        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();
        }
示例#8
0
 /// <summary>
 /// Constructs a FilterPassthroughResponseHandler instance.
 /// </summary>
 /// <param name="configuration">
 /// The shared, proxy configuration.
 /// </param>
 /// <exception cref="ArgumentException">
 /// If the supplied configuration is null or invalid, this constructor will throw.
 /// </exception>
 public FilterPassthroughResponseHandler(
     ProxyServerConfiguration configuration
     ) : base(configuration)
 {
     throw new NotImplementedException();
 }
示例#9
0
 /// <summary>
 /// Creates a new WindowsProxyServer instance. Really there should only ever be a single
 /// instance created at a time.
 /// </summary>
 /// <param name="configuration">
 /// The proxy server configuration to use.
 /// </param>
 /// <exception cref="ArgumentException">
 /// Will throw if any one of the callbacks in the supplied configuration are not defined.
 /// </exception>
 public WindowsProxyServer(ProxyServerConfiguration configuration) : base(configuration)
 {
 }
 /// <summary>
 /// Creates a new WindowsProxyServer instance. Really there should only ever be a single
 /// instance created at a time.
 /// </summary>
 /// <param name="configuration">
 /// The proxy server configuration to use.
 /// </param>
 /// <exception cref="ArgumentException">
 /// Will throw if any one of the callbacks in the supplied configuration are not defined.
 /// </exception>
 public WindowsProxyServer(ProxyServerConfiguration configuration) : base(configuration)
 {
     _sourceCfg = configuration;
 }