Skip to content

Commit 6068caf

Browse files
committed
Fix userAgent string in requests
Signed-off-by: Appu Goundan <appu@google.com>
1 parent bc1980b commit 6068caf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import dev.sigstore.forbidden.SuppressForbidden;
2525
import java.io.IOException;
2626
import javax.annotation.Nullable;
27+
import org.apache.http.HttpHeaders;
2728
import org.apache.http.conn.ssl.NoopHostnameVerifier;
2829
import 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

sigstore-java/src/main/java/dev/sigstore/oidc/client/WebOidcClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public OidcToken getIDToken(Map<String, String> env) throws OidcException {
164164
endpoints.getAuthEndpoint())
165165
.enablePKCE()
166166
.setScopes(Arrays.asList("openid", "email"))
167+
.setRequestInitializer((req) -> req.getHeaders().set("User-Agent", httpParams.getUserAgent()))
167168
.setCredentialCreatedListener(
168169
(credential, tokenResponse) ->
169170
memStoreFactory

0 commit comments

Comments
 (0)