You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/11/22 00:27:00 UTC

[jira] [Commented] (CB-13466) HEAD request to get real length should only be used for content encoding gzip on iOS

    [ https://issues.apache.org/jira/browse/CB-13466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16261757#comment-16261757 ] 

ASF GitHub Bot commented on CB-13466:
-------------------------------------

maverickmishra closed pull request #193: CB-13466: (ios) Only use HEAD to get real length if content encoding …
URL: https://github.com/apache/cordova-plugin-file-transfer/pull/193
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index d0584ad..b053460 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -726,9 +726,20 @@ - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLRespons
         self.bytesExpected = [response expectedContentLength];
         self.responseHeaders = [httpResponse allHeaderFields];
         if ((self.direction == CDV_TRANSFER_DOWNLOAD) && (self.responseCode == 200) && (self.bytesExpected == NSURLResponseUnknownLength)) {
-            // Kick off HEAD request to server to get real length
+            BOOL gzip = NO;
+            for (NSString *key in [self.responseHeaders allKeys]) {
+                if ( [@"Content-Encoding" caseInsensitiveCompare:key] == NSOrderedSame ) {
+                    if ( [@"gzip" caseInsensitiveCompare:[self.responseHeaders objectForKey:key]] == NSOrderedSame ){
+                        gzip = YES;
+                    }
+                }
+            }
+
+            // Kick off HEAD request to server to get real length if content encoding is gzip
             // bytesExpected will be updated when that response is returned
-            self.entityLengthRequest = [[CDVFileTransferEntityLengthRequest alloc] initWithOriginalRequest:connection.currentRequest andDelegate:self];
+            if ( gzip ) {
+                self.entityLengthRequest = [[CDVFileTransferEntityLengthRequest alloc] initWithOriginalRequest:connection.currentRequest andDelegate:self];
+            }
         }
     } else if ([response.URL isFileURL]) {
         NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[response.URL path] error:nil];


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> HEAD request to get real length should only be used for content encoding gzip on iOS
> ------------------------------------------------------------------------------------
>
>                 Key: CB-13466
>                 URL: https://issues.apache.org/jira/browse/CB-13466
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-file-transfer (DEPRECATED)
>            Reporter: Bobo Häggström
>
> When downloading files without file size (for example dynamically created content) the progress is not updated correct because of the HEAD request to get the real length. In the Android implementation which works, a HEAD request is only used for content encoding gzip. I think the iOS implementation should work the same way.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org