CompletableFuture processPossibleRedirects()

in src/main/java/com/spotify/github/v3/clients/GitHubClient.java [958:976]


  CompletableFuture<Response> processPossibleRedirects(
      final Response response, final AtomicBoolean redirected) {
    if (response.code() >= PERMANENT_REDIRECT
        && response.code() <= TEMPORARY_REDIRECT
        && !redirected.get()) {
      redirected.set(true);
      // redo the same request with a new URL
      final String newLocation = response.header("Location");
      final Request request =
          requestBuilder(newLocation)
              .url(newLocation)
              .method(response.request().method(), response.request().body())
              .build();
      // Do the new call and complete the original future when the new call completes
      return call(request);
    }

    return completedFuture(response);
  }