2424import dev .sigstore .forbidden .SuppressForbidden ;
2525import java .io .IOException ;
2626import javax .annotation .Nullable ;
27+ import org .apache .http .HttpHeaders ;
2728import org .apache .http .conn .ssl .NoopHostnameVerifier ;
2829import org .apache .http .impl .client .HttpClientBuilder ;
2930
@@ -36,8 +37,7 @@ public class HttpClients {
3637 * you need to also configure the response parser}.
3738 */
3839 public static HttpTransport newHttpTransport (HttpParams httpParams ) {
39- HttpClientBuilder hcb =
40- ApacheHttpTransport .newDefaultHttpClientBuilder ().setUserAgent (httpParams .getUserAgent ());
40+ HttpClientBuilder hcb = ApacheHttpTransport .newDefaultHttpClientBuilder ();
4141 if (httpParams .getAllowInsecureConnections ()) {
4242 hcb .setSSLHostnameVerifier (NoopHostnameVerifier .INSTANCE );
4343 }
@@ -46,17 +46,19 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) {
4646
4747 /** Create a new get requests with the httpParams applied and retries. */
4848 @ SuppressForbidden (reason = "HttpClients#newHttpTransport(HttpParams)" )
49- public static HttpRequestFactory newRequestFactory (HttpParams httpParams ) throws IOException {
49+ public static HttpRequestFactory newRequestFactory (HttpParams httpParams ) {
5050 return newRequestFactory (httpParams , null );
5151 }
5252
5353 /** Create a new get requests with the httpParams applied, retries and a response parser. */
5454 @ SuppressForbidden (reason = "HttpClients#newHttpTransport(HttpParams)" )
5555 public static HttpRequestFactory newRequestFactory (
56- HttpParams httpParams , @ Nullable ObjectParser responseParser ) throws IOException {
56+ HttpParams httpParams , @ Nullable ObjectParser responseParser ) {
5757 return HttpClients .newHttpTransport (httpParams )
5858 .createRequestFactory (
5959 request -> {
60+ request .setSuppressUserAgentSuffix (true );
61+ request .getHeaders ().set (HttpHeaders .USER_AGENT , httpParams .getUserAgent ());
6062 request .setConnectTimeout (httpParams .getTimeout () * 1000 );
6163 request .setReadTimeout (httpParams .getTimeout () * 1000 );
6264 request .setNumberOfRetries (3 ); // arbitrarily selected number of retries
0 commit comments