class RetryHttpRequestInitializer implements HttpRequestInitializer {

  @Override
  public void initialize(HttpRequest request) throws IOException {
    if (chained != null) {
      chained.initialize(request);
    }

    // Set a timeout for hanging-gets.
    // TODO: Do this exclusively for work requests.
    request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000);

    // Back off on retryable http errors.
    request.setUnsuccessfulResponseHandler(
        // A back-off multiplier of 2 raises the maximum request retrying time
        // to approximately 5 minutes (keeping other back-off parameters to
        // their default values).
        new LoggingHttpBackoffUnsuccessfulResponseHandler(
            new ExponentialBackOff.Builder().setNanoClock(nanoClock)
                                            .setMultiplier(2).build(),
            sleeper, ignoredResponseCodes));

    // Retry immediately on IOExceptions.
    LoggingHttpBackOffIOExceptionHandler loggingBackoffHandler =
        new LoggingHttpBackOffIOExceptionHandler(BackOff.ZERO_BACKOFF);
    request.setIOExceptionHandler(loggingBackoffHandler);

    // Set response initializer
    if (responseInterceptor != null) {
      request.setResponseInterceptor(responseInterceptor);
    }
  }

  public  RetryHttpRequestInitializer();
  @Deprecated public  RetryHttpRequestInitializer(@Nullable HttpRequestInitializer chained);
  public  RetryHttpRequestInitializer(Collection<Integer> additionalIgnoredResponseCodes);
  @Deprecated public  RetryHttpRequestInitializer(@Nullable HttpRequestInitializer chained,
      Collection<Integer> additionalIgnoredResponseCodes);
  public  RetryHttpRequestInitializer(
      Collection<Integer> additionalIgnoredResponseCodes,
      @Nullable HttpResponseInterceptor responseInterceptor);
  @Deprecated public  RetryHttpRequestInitializer(
      @Nullable HttpRequestInitializer chained,
      Collection<Integer> additionalIgnoredResponseCodes,
      @Nullable HttpResponseInterceptor responseInterceptor);
    RetryHttpRequestInitializer(@Nullable HttpRequestInitializer chained,
      NanoClock nanoClock, Sleeper sleeper, Collection<Integer> additionalIgnoredResponseCodes,
      HttpResponseInterceptor responseInterceptor);

}