Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries and support for IOExceptions retry #545

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
});
}
}
Loading