/**
   * Creates a new proxy server.
   *
   * @param port The port the server should run on.
   * @param responseFilters The {@link Map} of request domains to match with associated {@link
   *     HttpFilter}s for filtering responses to those requests.
   * @param chainProxyManager The proxy to send requests to if chaining proxies. Typically <code>
   *     null</code>.
   * @param ksm The key manager if running the proxy over SSL.
   * @param requestFilter Optional filter for modifying incoming requests. Often <code>null</code>.
   * @param clientChannelFactory The factory for creating outgoing channels to external sites.
   * @param timer The global timer for timing out idle connections.
   * @param serverChannelFactory The factory for creating listening channels for incoming
   *     connections.
   */
  public DefaultHttpProxyServer(
      final int port,
      final HttpResponseFilters responseFilters,
      final ChainProxyManager chainProxyManager,
      final KeyStoreManager ksm,
      final HttpRequestFilter requestFilter,
      final ClientSocketChannelFactory clientChannelFactory,
      final Timer timer,
      final ServerSocketChannelFactory serverChannelFactory,
      final ProxyCacheManager cacheManager) {
    this.port = port;
    this.responseFilters = responseFilters;
    this.ksm = ksm;
    this.requestFilter = requestFilter;
    this.chainProxyManager = chainProxyManager;
    this.clientChannelFactory = clientChannelFactory;
    this.timer = timer;
    this.serverChannelFactory = serverChannelFactory;
    if (cacheManager == null) {
      this.cacheManager = ProxyUtils.loadCacheManager();
    } else {
      this.cacheManager = cacheManager;
    }
    Thread.setDefaultUncaughtExceptionHandler(
        new UncaughtExceptionHandler() {
          public void uncaughtException(final Thread t, final Throwable e) {
            log.error("Uncaught throwable", e);
          }
        });

    // Use our thread names so users know there are LittleProxy threads.
    ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
    this.serverBootstrap = new ServerBootstrap(serverChannelFactory);
  }
 /**
  * Creates a new proxy server.
  *
  * @param port The port the server should run on.
  * @param responseFilters The {@link Map} of request domains to match with associated {@link
  *     HttpFilter}s for filtering responses to those requests.
  * @param chainProxyManager The proxy to send requests to if chaining proxies. Typically <code>
  *     null</code>.
  * @param ksm The key manager if running the proxy over SSL.
  * @param requestFilter Optional filter for modifying incoming requests. Often <code>null</code>.
  * @param clientChannelFactory The factory for creating outgoing channels to external sites.
  * @param timer The global timer for timing out idle connections.
  * @param serverChannelFactory The factory for creating listening channels for incoming
  *     connections.
  */
 public DefaultHttpProxyServer(
     final int port,
     final HttpResponseFilters responseFilters,
     final ChainProxyManager chainProxyManager,
     final KeyStoreManager ksm,
     final HttpRequestFilter requestFilter,
     final ClientSocketChannelFactory clientChannelFactory,
     final Timer timer,
     final ServerSocketChannelFactory serverChannelFactory) {
   this(
       port,
       responseFilters,
       chainProxyManager,
       ksm,
       requestFilter,
       clientChannelFactory,
       timer,
       serverChannelFactory,
       ProxyUtils.loadCacheManager());
 }