/**
   * Create an {@link AsyncHttpClientConfig} instance based on the values from {@link
   * RepositorySystemSession}
   *
   * @param session {link RepositorySystemSession}
   * @return a configured instance of
   */
  private AsyncHttpClientConfig createConfig(
      RepositorySystemSession session, RemoteRepository repository, boolean useCompression) {
    AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder();

    String userAgent =
        ConfigUtils.getString(
            session,
            ConfigurationProperties.DEFAULT_USER_AGENT,
            ConfigurationProperties.USER_AGENT);
    if (!StringUtils.isEmpty(userAgent)) {
      configBuilder.setUserAgent(userAgent);
    }
    int connectTimeout =
        ConfigUtils.getInteger(
            session,
            ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT,
            ConfigurationProperties.CONNECT_TIMEOUT);

    configBuilder.setConnectionTimeoutInMs(connectTimeout);
    configBuilder.setCompressionEnabled(useCompression);
    configBuilder.setFollowRedirects(true);
    configBuilder.setRequestTimeoutInMs(
        ConfigUtils.getInteger(
            session,
            ConfigurationProperties.DEFAULT_REQUEST_TIMEOUT,
            ConfigurationProperties.REQUEST_TIMEOUT));

    configBuilder.setProxyServer(getProxy(repository));
    configBuilder.setRealm(getRealm(repository));

    return configBuilder.build();
  }
  /**
   * Create an {@link org.sonatype.aether.connector.async.AsyncRepositoryConnector} instance which
   * connect to the {@link RemoteRepository}
   *
   * @param repository the remote repository
   * @param session the {@link RepositorySystemSession}
   * @param logger the logger.
   * @throws NoRepositoryConnectorException
   */
  public AsyncRepositoryConnector(
      RemoteRepository repository,
      RepositorySystemSession session,
      FileProcessor fileProcessor,
      Logger logger)
      throws NoRepositoryConnectorException {
    this.logger = logger;
    this.repository = repository;
    this.listener = session.getTransferListener();
    this.fileProcessor = fileProcessor;
    this.session = session;

    if (!"default".equals(repository.getContentType())) {
      throw new NoRepositoryConnectorException(repository);
    }

    if (!repository.getProtocol().regionMatches(true, 0, "http", 0, "http".length())
        && !repository.getProtocol().regionMatches(true, 0, "dav", 0, "dav".length())) {
      throw new NoRepositoryConnectorException(repository);
    }

    AsyncHttpClientConfig config = createConfig(session, repository, true);
    httpClient = new AsyncHttpClient(new NettyAsyncHttpProvider(config));

    checksumAlgos = new LinkedHashMap<String, String>();
    checksumAlgos.put("SHA-1", ".sha1");
    checksumAlgos.put("MD5", ".md5");

    disableResumeSupport =
        ConfigUtils.getBoolean(session, false, "aether.connector.ahc.disableResumable");
    maxIOExceptionRetry = ConfigUtils.getInteger(session, 3, "aether.connector.ahc.resumeRetry");

    this.headers = new FluentCaseInsensitiveStringsMap();
    Map<?, ?> headers =
        ConfigUtils.getMap(
            session,
            null,
            ConfigurationProperties.HTTP_HEADERS + "." + repository.getId(),
            ConfigurationProperties.HTTP_HEADERS);
    if (headers != null) {
      for (Map.Entry<?, ?> entry : headers.entrySet()) {
        if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
          this.headers.add(entry.getKey().toString(), entry.getValue().toString());
        }
      }
    }
  }