Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.client.util.ObjectParser;
import dev.sigstore.forbidden.SuppressForbidden;
import java.io.IOException;
import javax.annotation.Nullable;
import org.apache.http.HttpHeaders;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;

Expand All @@ -36,8 +36,7 @@ public class HttpClients {
* you need to also configure the response parser}.
*/
public static HttpTransport newHttpTransport(HttpParams httpParams) {
HttpClientBuilder hcb =
ApacheHttpTransport.newDefaultHttpClientBuilder().setUserAgent(httpParams.getUserAgent());
HttpClientBuilder hcb = ApacheHttpTransport.newDefaultHttpClientBuilder();
if (httpParams.getAllowInsecureConnections()) {
hcb.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}
Expand All @@ -46,17 +45,19 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) {

/** Create a new get requests with the httpParams applied and retries. */
@SuppressForbidden(reason = "HttpClients#newHttpTransport(HttpParams)")
public static HttpRequestFactory newRequestFactory(HttpParams httpParams) throws IOException {
public static HttpRequestFactory newRequestFactory(HttpParams httpParams) {
return newRequestFactory(httpParams, null);
}

/** Create a new get requests with the httpParams applied, retries and a response parser. */
@SuppressForbidden(reason = "HttpClients#newHttpTransport(HttpParams)")
public static HttpRequestFactory newRequestFactory(
HttpParams httpParams, @Nullable ObjectParser responseParser) throws IOException {
HttpParams httpParams, @Nullable ObjectParser responseParser) {
return HttpClients.newHttpTransport(httpParams)
.createRequestFactory(
request -> {
request.setSuppressUserAgentSuffix(true);
request.getHeaders().set(HttpHeaders.USER_AGENT, httpParams.getUserAgent());
request.setConnectTimeout(httpParams.getTimeout() * 1000);
request.setReadTimeout(httpParams.getTimeout() * 1000);
request.setNumberOfRetries(3); // arbitrarily selected number of retries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public OidcToken getIDToken(Map<String, String> env) throws OidcException {
endpoints.getAuthEndpoint())
.enablePKCE()
.setScopes(Arrays.asList("openid", "email"))
.setRequestInitializer(
(req) -> req.getHeaders().set("User-Agent", httpParams.getUserAgent()))
.setCredentialCreatedListener(
(credential, tokenResponse) ->
memStoreFactory
Expand Down
Loading