Skip to content

Commit

Permalink
Merge pull request #545 from sigstore/retries
Browse files Browse the repository at this point in the history
Add retries and support for IOExceptions retry
  • Loading branch information
loosebazooka authored Oct 18, 2023
2 parents 68498f2 + 3f1346d commit e174366
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package dev.sigstore.http;

import com.google.api.client.http.HttpBackOffIOExceptionHandler;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.v2.ApacheHttpTransport;
import com.google.api.client.util.ExponentialBackOff;
import java.io.IOException;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
Expand All @@ -38,15 +40,18 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) {
return new ApacheHttpTransport(hcb.build());
}

/** Create a new get requests with the httpParams applied and exponential backoff retries. */
/** Create a new get requests with the httpParams applied and retries. */
public static HttpRequestFactory newRequestFactory(HttpParams httpParams) throws IOException {
return HttpClients.newHttpTransport(httpParams)
.createRequestFactory(
request -> {
request.setConnectTimeout(httpParams.getTimeout() * 1000);
request.setReadTimeout(httpParams.getTimeout() * 1000);
request.setNumberOfRetries(3); // arbitrarily selected number of retries
request.setUnsuccessfulResponseHandler(
UnsuccessfulResponseHandler.newUnsuccessfulResponseHandler());
request.setIOExceptionHandler(
new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
});
}
}

0 comments on commit e174366

Please sign in to comment.