Skip to content

Commit d2223e3

Browse files
authored
Merge pull request #95 from browserstack/LOC-6208-handle-invalid-json-source-url
Fix: 400 status code bad request in case of invalid json fetch binary URL
2 parents 4d4c967 + b772742 commit d2223e3

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<groupId>com.browserstack</groupId>
44
<artifactId>browserstack-local-java</artifactId>
55
<packaging>jar</packaging>
6-
<version>1.1.6</version>
6+
<version>1.1.7</version>
77

88
<name>browserstack-local-java</name>
99
<description>Java bindings for BrowserStack Local</description>

src/main/java/com/browserstack/local/Local.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Local {
2323
private LocalProcess proc = null;
2424

2525
// Current version of binding package, used for --source option of binary
26-
private static final String packageVersion = "1.1.6";
26+
private static final String packageVersion = "1.1.7";
2727
private final Map<String, String> parameters;
2828
private final Map<String, String> avoidValueParameters;
2929

src/main/java/com/browserstack/local/LocalBinary.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ private void fetchSourceUrl() throws LocalException {
207207
connection.setRequestProperty("Content-Type", "application/json");
208208
connection.setRequestProperty("User-Agent", "browserstack-local-java/" + Local.getPackageVersion());
209209
connection.setRequestProperty("Accept", "application/json");
210-
if (fallbackEnabled) connection.setRequestProperty("X-Local-Fallback-Cloudflare", "true");
211210

212-
String jsonInput = "{\"auth_token\": \"" + key + (fallbackEnabled ? ("\", \"error_message\": \"" + downloadFailureThrowable.getMessage()) + "\"" : "\"") + "}";
211+
JSONObject inputParams = new JSONObject();
212+
inputParams.put("auth_token", this.key);
213+
if (fallbackEnabled) {
214+
connection.setRequestProperty("X-Local-Fallback-Cloudflare", "true");
215+
inputParams.put("error_message", downloadFailureThrowable.getMessage());
216+
}
217+
String jsonInputParams = inputParams.toString();
213218

214219
try (OutputStream os = connection.getOutputStream()) {
215-
byte[] input = jsonInput.getBytes("utf-8");
220+
byte[] input = jsonInputParams.getBytes("utf-8");
216221
os.write(input, 0, input.length);
217222
}
218223

0 commit comments

Comments
 (0)