Skip to content

Commit 039f828

Browse files
committed
refactor(WatsonService): Set User-Agent with just core info if it's not supplied by an outside SDK
1 parent 103cf3a commit 039f828

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/java/com/ibm/cloud/sdk/core/service/WatsonService.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.ibm.cloud.sdk.core.service.security.IamOptions;
3737
import com.ibm.cloud.sdk.core.service.security.IamTokenManager;
3838
import com.ibm.cloud.sdk.core.util.CredentialUtils;
39+
import com.ibm.cloud.sdk.core.util.RequestUtils;
3940
import com.ibm.cloud.sdk.core.util.ResponseConverterUtils;
4041
import jersey.repackaged.jsr166e.CompletableFuture;
4142
import okhttp3.Call;
@@ -193,16 +194,28 @@ public void configureClient(HttpConfigOptions options) {
193194
private Call createCall(final Request request) {
194195
final Request.Builder builder = request.newBuilder();
195196

197+
if (request.headers().get(HttpHeaders.USER_AGENT) == null) {
198+
setUserAgent(builder);
199+
}
196200
setDefaultHeaders(builder);
197-
198201
setAuthentication(builder);
199202

200203
final Request newRequest = builder.build();
201204
return client.newCall(newRequest);
202205
}
203206

204207
/**
205-
* Sets the default headers including User-Agent.
208+
* Set the User-Agent header.
209+
*
210+
* @param builder the Request builder
211+
*/
212+
private void setUserAgent(final Request.Builder builder) {
213+
String userAgent = RequestUtils.getUserAgent();
214+
builder.header(HttpHeaders.USER_AGENT, userAgent);
215+
}
216+
217+
/**
218+
* Sets the default headers.
206219
*
207220
* @param builder the new default headers
208221
*/

0 commit comments

Comments
 (0)