<commit_before>package com.google.sitebricks.client;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.Realm;
import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response;
import net.jcip.annotations.ThreadSafe;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author <NAME> (<EMAIL>)
 */
@ThreadSafe
class AHCWebClient<T> implements WebClient<T> {
  private final Injector injector;
  private final String url;
  private final Map<String, String> headers;
  private final Class<T> transporting;
  private final Key<? extends Transport> transport;
  private final AsyncHttpClient httpClient;

  private final Web.Auth authType;
  private final String username;
  private final String password;

  public AHCWebClient(Injector injector, Web.Auth authType, String username, String password, String url, Map<String, String> headers, Class<T> transporting, Key<? extends Transport> transport) {

    this.injector = injector;

    this.url = url;
    this.headers = (null == headers) ? null : ImmutableMap.copyOf(headers);

    this.authType = authType;
    this.username = username;
    this.password = password;
    this.transporting = transporting;
    this.transport = transport;

    // configure auth
    AsyncHttpClientConfig.Builder c = new AsyncHttpClientConfig.Builder();
    if (null != authType) {
      Realm.RealmBuilder b = new Realm.RealmBuilder();
      // TODO: Add support for Kerberos and SPNEGO
      Realm.AuthScheme scheme = authType.equals(Web.Auth.BASIC) ? Realm.AuthScheme.BASIC : Realm.AuthScheme.DIGEST;
      b.setPrincipal(username).setPassword(password).setScheme(scheme);
      c.setRealm(b.build());
    }

    this.httpClient = new AsyncHttpClient(c.build());

  }

  private WebResponse simpleRequest(RequestBuilder requestBuilder) {

    // set request headers as necessary
    if (null != headers)
      for (Map.Entry<String, String> header : headers.entrySet())
        requestBuilder.addHeader(header.getKey(), header.getValue());

    try {

      Response r = httpClient.executeRequest(requestBuilder.build()).get();

      return new WebResponseImpl(injector, r);
    } catch (IOException e) {
      throw new TransportException(e);
    } catch (InterruptedException e) {
      throw new TransportException(e);
    } catch (ExecutionException e) {
      throw new TransportException(e);
    }
  }

  private WebResponse request(RequestBuilder requestBuilder, T t) {

    // set request headers as necessary
    if (null != headers)
      for (Map.Entry<String, String> header : headers.entrySet())
        requestBuilder.addHeader(header.getKey(), header.getValue());
<commit_msg>- remove unused fields<commit_after>package com.google.sitebricks.client;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.Realm;
import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response;
import net.jcip.annotations.ThreadSafe;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author <NAME> (<EMAIL>)
 */
@ThreadSafe
class AHCWebClient<T> implements WebClient<T> {
  private final Injector injector;
  private final String url;
  private final Map<String, String> headers;
  private final Class<T> transporting;
  private final Key<? extends Transport> transport;
  private final AsyncHttpClient httpClient;

  public AHCWebClient(Injector injector, Web.Auth authType, String username, String password, String url, Map<String, String> headers, Class<T> transporting, Key<? extends Transport> transport) {

    this.injector = injector;
    this.url = url;
    this.headers = (null == headers) ? null : ImmutableMap.copyOf(headers);
    this.transporting = transporting;
    this.transport = transport;

    // configure auth
    AsyncHttpClientConfig.Builder c = new AsyncHttpClientConfig.Builder();
    if (null != authType) {
      Realm.RealmBuilder b = new Realm.RealmBuilder();
      // TODO: Add support for Kerberos and SPNEGO
      Realm.AuthScheme scheme = authType.equals(Web.Auth.BASIC) ? Realm.AuthScheme.BASIC : Realm.AuthScheme.DIGEST;
      b.setPrincipal(username).setPassword(password).setScheme(scheme);
      c.setRealm(b.build());
    }

    this.httpClient = new AsyncHttpClient(c.build());
  }

  private WebResponse simpleRequest(RequestBuilder requestBuilder) {

    // set request headers as necessary
    if (null != headers)
      for (Map.Entry<String, String> header : headers.entrySet())
        requestBuilder.addHeader(header.getKey(), header.getValue());

    try {

      Response r = httpClient.executeRequest(requestBuilder.build()).get();

      return new WebResponseImpl(injector, r);
    } catch (IOException e) {
      throw new TransportException(e);
    } catch (InterruptedException e) {
      throw new TransportException(e);
    } catch (ExecutionException e) {
      throw new TransportException(e);
    }
  }

  private WebResponse request(RequestBuilder requestBuilder, T t) {

    // set request headers as necessary
    if (null != headers)
      for (Map.Entry<String, String> header : headers.entrySet())
        requestBuilder.addHeader(header.getKey(), header.getValue());

{'fraction_non_alphanumeric': 0.1087634222376169, 'fraction_numerical': 0.0, 'mean_word_length': 4.110619469026549, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6892237', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1634, 'n_words': 413}