Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer-Encoding: chunked broken? #443

Closed
th317erd opened this issue Sep 27, 2019 · 3 comments
Closed

Transfer-Encoding: chunked broken? #443

th317erd opened this issue Sep 27, 2019 · 3 comments

Comments

@th317erd
Copy link

Info:
rn-fetch-blob: 0.11.1
react-native: 0.61.1
platform: Android

Issue:
I keep getting the error from rn-fetch-blob: "RNFetchBlob failed. Download interrupted."

What:
I am trying to download a PDF that is sent from the server with Transfer-Encoding: chunked. Here is the response headers from curl (curl used to verify headers):

< HTTP/1.1 200 OK
< Content-Type: application/pdf
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< Cache-Control: private
< Referrer-Policy: strict-origin-when-cross-origin
< X-Permitted-Cross-Domain-Policies: none
< X-XSS-Protection: 1; mode=block
< X-Request-Id: 77793746-2596-4ea6-91d0-04a2a282efaf
< Content-Disposition: attachment; filename="C0RF196576.pdf"
< X-Download-Options: noopen
< Content-Transfer-Encoding: binary
< ETag: W/"79cf291140e5b219daa1387b23dd4476"
< X-Frame-Options: SAMEORIGIN
< X-Runtime: 2.455705
< X-Content-Type-Options: nosniff
< Date: Fri, 27 Sep 2019 00:51:57 GMT
< X-Powered-By: Phusion Passenger Enterprise 6.0.3
< Server: nginx/1.17.3 + Phusion Passenger 6.0.3
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< x-frame-options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< x-frame-options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< 

Inside rn-fetch-blob source code I see the following (RNFetchBlobReq.java):

           case FileStorage:
                ResponseBody responseBody = resp.body();

                try {
                    // In order to write response data to `destPath` we have to invoke this method.
                    // It uses customized response body which is able to report download progress
                    // and write response data to destination path.
                    responseBody.bytes();
                } catch (Exception ignored) {
                    ignored.printStackTrace();
                }

                RNFetchBlobFileResp rnFetchBlobFileResp = (RNFetchBlobFileResp) responseBody;

                if(rnFetchBlobFileResp != null && rnFetchBlobFileResp.isDownloadComplete() == false){
                    callback.invoke("RNFetchBlob failed. Download interrupted.", null);
                }
                else {
                    this.destPath = this.destPath.replace("?append=true", "");
                    callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
                }
                break;

The rnFetchBlobFileResp.isDownloadComplete() is where it is failing. Inside that method we have (RNFetchBlobFileResp.java):

public boolean isDownloadComplete() {
        return bytesDownloaded == contentLength();
    }

And contentLength() we have (RNFetchBlobBody.java):

@Override
    public long contentLength() {
        return chunkedEncoding ? -1 : contentLength;
    }

So unless I am reading this wrong, the contentLength for "chunked" encoding will always be -1, which will never match bytesDownloaded?

Am I reading this correctly? Doesn't this mean Transfer-Encoding: chunked downloads will always fail?

@Traviskn
Copy link

This regression seems to have been caused by #396

@Traviskn
Copy link

I have reverted #396 and published a new version, 0.11.2

@th317erd
Copy link
Author

Thank you! 😃

@Traviskn Traviskn closed this as completed Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants