question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HEAD response from AWS in Android fails

See original GitHub issue

Version: 0.10.13

Requesting HEAD from AWS S3 should return the headers of an object. The headers contain Content-Length header which represents the size of the object.

And as it is known HEAD responses have no body.

Anyway in RNFetchBlobReq.java the HEAD response is handled as it would have body and in line 505 bytes() method is called:

byte[] b = resp.body().bytes();

And in okhttp3 an IOException is raised if Content-Length does not match the body length:

  public final byte[] bytes() throws IOException {
    long contentLength = contentLength();
    if (contentLength > Integer.MAX_VALUE) {
      throw new IOException("Cannot buffer entire body for content length: " + contentLength);
    }

    BufferedSource source = source();
    byte[] bytes;
    try {
      bytes = source.readByteArray();
    } finally {
      Util.closeQuietly(source);
    }
    if (contentLength != -1 && contentLength != bytes.length) {
      throw new IOException("Content-Length ("
          + contentLength
          + ") and stream length ("
          + bytes.length
          + ") disagree");
    }
    return bytes;
  }

So this ruins pretty bad requesting metadata from AWS.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
sakaritcommented, Feb 6, 2019

@JofBigHealth Hey, so glad that I could help you out. 😃

This bug made me very frustrated back then and I researched and researched it until found that last resort like solution.

Really hope that it will get fixed some day, rn-fetch-blob is good stuff otherwise!

0reactions
hurajgorcommented, Oct 25, 2022

Note: the problem also seems related to rn-fetch-blob using .byteStream() ahead of .body() as per this StackOverflow issue. Possible? By hard-coding a replacement to .byteStream() here I was able to avoid the exception.

Hey @JofBigHealth / @sakarit,

I tried using your approach but I’m not getting any response back even though the server is sending back the response. Could you please help me out with it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Responses - Amazon Simple Storage Service
Lists and describes the Amazon S3 error responses and their associated HTTP status codes.
Read more >
HeadObject - Amazon Simple Storage Service
The HEAD action retrieves metadata from an object without returning the object itself. This action is useful if you're only interested in an...
Read more >
HTTP 400 status code (Bad Request) - Amazon CloudFront
When the deployment is complete, the distribution's status changes to Deployed, and you should stop receiving the AuthorizationHeaderMalformed error responses.
Read more >
Signing and authenticating REST requests
This topic explains authenticating requests using Signature Version 2. Amazon S3 now supports the latest Signature Version 4. This latest signature version ...
Read more >
Resolve Access Denied errors from a CloudFront distribution ...
I'm using an Amazon Simple Storage Service (Amazon S3) bucket as the origin of my Amazon CloudFront distribution. I'm using the S3 REST...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found