Skip to content

Commit e485a2f

Browse files
author
jchen293
authored
Backports User-Agent header changes (#154)
1 parent 6255150 commit e485a2f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
=== Next Release
2+
- Backports User-Agent header changes
3+
14
=== 4.0.4 2020-10-29
25
- Actually bump User-Agent (which hadn't been bumped since 4.0.0)
36

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,25 @@ private static String urlEncodePair(String k, String v) throws UnsupportedEncodi
148148
static Map<String, String> getHeaders(String apiKey) {
149149
Map<String, String> headers = new HashMap<String, String>();
150150
headers.put("Accept-Charset", CHARSET);
151-
headers.put("User-Agent", String.format("EasyPost/v2 JavaClient/%s", EasyPost.VERSION));
151+
headers.put("User-Agent", String.format("EasyPost/v2 JavaClient/%s Java/%s OS/%s OSVersion/%s OSArch/%s " +
152+
"Implementation/%s", EasyPost.VERSION, System.getProperty("java.version"),
153+
convertSpaceToHyphen(System.getProperty("os.name")), System.getProperty("os.version"),
154+
convertSpaceToHyphen(System.getProperty("os.arch")),
155+
convertSpaceToHyphen(System.getProperties().getProperty("java.vm.name"))));
152156

153157
if (apiKey == null) {
154158
apiKey = EasyPost.apiKey;
155159
}
156160

157161
headers.put("Authorization", String.format("Bearer %s", apiKey));
158162

159-
// debug headers
160-
String[] propertyNames = { "os.name", "os.version", "os.arch",
161-
"java.version", "java.vendor", "java.vm.version",
162-
"java.vm.vendor" };
163-
Map<String, String> propertyMap = new HashMap<String, String>();
164-
for (String propertyName : propertyNames) {
165-
propertyMap.put(propertyName, System.getProperty(propertyName));
166-
}
167-
propertyMap.put("lang", "Java");
168-
propertyMap.put("publisher", "EasyPost");
169-
headers.put("X-Client-User-Agent", gson.toJson(propertyMap));
170-
171-
return headers;
163+
return headers;
172164
}
173165

166+
private static String convertSpaceToHyphen(String string) {
167+
return string.replace(' ', '-');
168+
}
169+
174170
private static javax.net.ssl.HttpsURLConnection createEasyPostConnection(String url, String apiKey) throws IOException {
175171
URL easypostURL = null;
176172
String customURLStreamHandlerClassName = System.getProperty(CUSTOM_URL_STREAM_HANDLER_PROPERTY_NAME, null);

0 commit comments

Comments
 (0)