Be more generous about acceptable JSON content-types
Fixes a problem when reading data from a chromedriver
when using passthrough mode.
Also use a try-with-resources to make sure that we
close the inputstream when reading an entity from a
response.
@@ -322,9 +322,9 @@ private void updateHubNewSeleniumSession(String content) {
Header h = proxyResponse.getFirstHeader("Location");
if (h == null) {
if (isSuccessJsonResponse(proxyResponse) && proxyResponse.getEntity() != null) {
- InputStream stream = proxyResponse.getEntity().getContent();
+ try (InputStream stream = proxyResponse.getEntity().getContent()) {
consumedData = ByteStreams.toByteArray(stream);
- stream.close();
+ }
String contentString = new String(consumedData, Charsets.UTF_8);
ExternalSessionKey key = ExternalSessionKey.fromJsonResponseBody(contentString);
@@ -355,7 +355,7 @@ private static boolean isSuccessJsonResponse(HttpResponse response) {
continue;
}
- if (MediaType.JSON_UTF_8.is(type)) {
+ if (MediaType.JSON_UTF_8.is(type) || MediaType.JAVASCRIPT_UTF_8.is(type)) {
return true;
}
}
