2222import com .google .api .client .util .ExponentialBackOff ;
2323import com .google .api .client .util .ObjectParser ;
2424import dev .sigstore .forbidden .SuppressForbidden ;
25- import java .io .IOException ;
2625import javax .annotation .Nullable ;
26+ import org .apache .http .HttpHeaders ;
2727import org .apache .http .conn .ssl .NoopHostnameVerifier ;
2828import org .apache .http .impl .client .HttpClientBuilder ;
2929
@@ -36,8 +36,7 @@ public class HttpClients {
3636 * you need to also configure the response parser}.
3737 */
3838 public static HttpTransport newHttpTransport (HttpParams httpParams ) {
39- HttpClientBuilder hcb =
40- ApacheHttpTransport .newDefaultHttpClientBuilder ().setUserAgent (httpParams .getUserAgent ());
39+ HttpClientBuilder hcb = ApacheHttpTransport .newDefaultHttpClientBuilder ();
4140 if (httpParams .getAllowInsecureConnections ()) {
4241 hcb .setSSLHostnameVerifier (NoopHostnameVerifier .INSTANCE );
4342 }
@@ -46,17 +45,19 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) {
4645
4746 /** Create a new get requests with the httpParams applied and retries. */
4847 @ SuppressForbidden (reason = "HttpClients#newHttpTransport(HttpParams)" )
49- public static HttpRequestFactory newRequestFactory (HttpParams httpParams ) throws IOException {
48+ public static HttpRequestFactory newRequestFactory (HttpParams httpParams ) {
5049 return newRequestFactory (httpParams , null );
5150 }
5251
5352 /** Create a new get requests with the httpParams applied, retries and a response parser. */
5453 @ SuppressForbidden (reason = "HttpClients#newHttpTransport(HttpParams)" )
5554 public static HttpRequestFactory newRequestFactory (
56- HttpParams httpParams , @ Nullable ObjectParser responseParser ) throws IOException {
55+ HttpParams httpParams , @ Nullable ObjectParser responseParser ) {
5756 return HttpClients .newHttpTransport (httpParams )
5857 .createRequestFactory (
5958 request -> {
59+ request .setSuppressUserAgentSuffix (true );
60+ request .getHeaders ().set (HttpHeaders .USER_AGENT , httpParams .getUserAgent ());
6061 request .setConnectTimeout (httpParams .getTimeout () * 1000 );
6162 request .setReadTimeout (httpParams .getTimeout () * 1000 );
6263 request .setNumberOfRetries (3 ); // arbitrarily selected number of retries
0 commit comments