Exemple #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>
        /// Creates a new proxy server 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 ProxyServer(ProxyServerConfiguration configuration)
        {
            _configuration = configuration;

            if (_configuration == null || !_configuration.IsValid)
            {
                throw new ArgumentException("Configuration is null or invalid. Ensure that all callbacks are defined.");
            }

            _tlsConnAdapter = new TlsSniConnectionAdapter(CreateCertificateStore(configuration.AuthorityName ?? "CitadelCore"));
            _fwCallback     = configuration.FirewallCheckCallback ?? throw new ArgumentException("The firewall callback MUST be defined.", nameof(configuration));

            _replayResponseFactory = new ReplayResponseHandlerFactory();
            _httpResponseFactory   = new FilterResponseHandlerFactory(_configuration, _replayResponseFactory);

            // Hook the cert verification callback.
            ServicePointManager.ServerCertificateValidationCallback += CertificateVerificationHandler;
        }
 public PrivateServerStartup(IHostingEnvironment env, ReplayResponseHandlerFactory handlerFactory)
 {
     _handlerFactory = handlerFactory;
 }