Permalink
Browse files

Fix `HEAD` http requests in Android

Summary:
Closes #7463.

This PR fixes the `HEAD` http requests in Android.
In Android all the HEAD http requests will fail, even if the request succeeds in the native layer due to an issue in the communication with the `OkHttp`.
Closes #14289

Differential Revision: D5166130

Pulled By: hramos

fbshipit-source-id: a7a0deee0fcb5f6a645c07d4e6f4386b5f550e31
  • Loading branch information...
SandroMachado authored and facebook-github-bot committed Jul 20, 2017
1 parent 8e8fecd commit bdd46aa28392004c7d29e59434d6c8d95c6f36c8
@@ -369,7 +369,19 @@ public void onResponse(Call call, Response response) throws IOException {
// Otherwise send the data in one big chunk, in the format that JS requested.
String responseString = "";
if (responseType.equals("text")) {
responseString = responseBody.string();
try {
responseString = responseBody.string();
} catch (IOException e) {
if (response.request().method().equalsIgnoreCase("HEAD")) {
// The request is an `HEAD` and the body is empty,
// the OkHttp will produce an exception.
// Ignore the exception to not invalidate the request in the
// Javascript layer.
// Introduced to fix issue #7463.
} else {
ResponseUtil.onRequestError(eventEmitter, requestId, e.getMessage(), e);
}
}
} else if (responseType.equals("base64")) {
responseString = Base64.encodeToString(responseBody.bytes(), Base64.NO_WRAP);
}

0 comments on commit bdd46aa

Please sign in to comment.