Skip to content

Commit c6625c6

Browse files
author
jchen293
authored
Adds OS specific details to the user-agent header (#153)
1 parent 84c91b5 commit c6625c6

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
functions.
77
- `getSmartrates()` -> `smartrates()`
88
- `getLowestSmartRate()` -> `findLowestSmartrate()`
9+
- Adds OS specific details to the user-agent header
910

1011
## v5.5.0 (2022-06-21)
1112

src/main/java/com/easypost/net/EasyPostResource.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,36 +266,25 @@ private static String urlEncodePair(final String key, final String value) throws
266266
static Map<String, String> getHeaders(String apiKey) {
267267
Map<String, String> headers = new HashMap<String, String>();
268268
headers.put("Accept-Charset", CHARSET);
269-
headers.put("User-Agent", String.format("EasyPost/v2 JavaClient/%s Java/%s", EasyPost.VERSION,
270-
System.getProperty("java.version")));
269+
headers.put("User-Agent", String.format("EasyPost/v2 JavaClient/%s Java/%s OS/%s OSVersion/%s OSArch/%s " +
270+
"Implementation/%s", EasyPost.VERSION, System.getProperty("java.version"),
271+
convertSpaceToHyphen(System.getProperty("os.name")), System.getProperty("os.version"),
272+
convertSpaceToHyphen(System.getProperty("os.arch")),
273+
convertSpaceToHyphen(System.getProperties().getProperty("java.vm.name"))));
271274

272275
if (apiKey == null) {
273276
apiKey = EasyPost.apiKey;
274277
}
275278

276279
headers.put("Authorization", String.format("Bearer %s", apiKey));
277280

278-
// debug headers
279-
String[] propertyNames = {
280-
"os.name",
281-
"os.version",
282-
"os.arch",
283-
"java.version",
284-
"java.vendor",
285-
"java.vm.version",
286-
"java.vm.vendor"
287-
};
288-
Map<String, String> propertyMap = new HashMap<String, String>();
289-
for (String propertyName : propertyNames) {
290-
propertyMap.put(propertyName, System.getProperty(propertyName));
291-
}
292-
propertyMap.put("lang", "Java");
293-
propertyMap.put("publisher", "EasyPost");
294-
headers.put("X-Client-User-Agent", GSON.toJson(propertyMap));
295-
296281
return headers;
297282
}
298283

284+
private static String convertSpaceToHyphen(String string) {
285+
return string.replace(' ', '-');
286+
}
287+
299288
private static javax.net.ssl.HttpsURLConnection createEasyPostConnection(final String url, final String apiKey,
300289
final String method) throws IOException {
301290
HttpsURLConnection conn = null;

src/test/java/com/easypost/TestUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ public enum ApiKey {
1818
PRODUCTION
1919
}
2020

21-
private static final String API_KEY_FAILED_TO_PULL = "couldnotpullapikey";
21+
private static final String API_KEY_FAILED_TO_PULL = "couldNotPullApiKey";
2222
private static final String CASSETTES_PATH = "src/test/cassettes";
2323
private static final java.util.List<String> HEADER_CENSORS = new ArrayList<String>() {{
2424
add("Authorization");
2525
add("User-Agent");
26-
add("X-Client-User-Agent");
2726
}};
2827
private static final List<String> QUERY_CENSORS = new ArrayList<String>() {{
2928
add("card[cvc]");

0 commit comments

Comments
 (0)