cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-plugin-file-transfer git commit: CB-6928 Wrong behaviour transferring cacheable content
Date Wed, 11 Nov 2015 06:52:07 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master 5857384b9 -> 189942284


CB-6928 Wrong behaviour transferring cacheable content

Adds support of 304 handling for iOS, Windows and adds a corresponding test


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/18994228
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/18994228
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/18994228

Branch: refs/heads/master
Commit: 189942284a64fb3de11e81f3fb41af4e102b1ac6
Parents: 5857384
Author: daserge <v-seshak@microsoft.com>
Authored: Mon Nov 9 16:25:03 2015 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Wed Nov 11 09:46:17 2015 +0300

----------------------------------------------------------------------
 src/ios/CDVFileTransfer.h        |  3 ++-
 src/ios/CDVFileTransfer.m        |  3 ++-
 src/windows/FileTransferProxy.js |  3 +++
 tests/tests.js                   | 26 +++++++++++++++++++++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/18994228/src/ios/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.h b/src/ios/CDVFileTransfer.h
index 9c4bcf1..bb5fa13 100644
--- a/src/ios/CDVFileTransfer.h
+++ b/src/ios/CDVFileTransfer.h
@@ -25,7 +25,8 @@ enum CDVFileTransferError {
     FILE_NOT_FOUND_ERR = 1,
     INVALID_URL_ERR = 2,
     CONNECTION_ERR = 3,
-    CONNECTION_ABORTED = 4
+    CONNECTION_ABORTED = 4,
+    NOT_MODIFIED = 5
 };
 typedef int CDVFileTransferError;
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/18994228/src/ios/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index 2655e48..dca440a 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -592,7 +592,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self.filePlugin
makeEntryForURL:self.targetURL]];
         } else {
             downloadResponse = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
-            CDVFileTransferError errorCode = self.responseCode == 404 ? FILE_NOT_FOUND_ERR
: CONNECTION_ERR;
+            CDVFileTransferError errorCode = self.responseCode == 404 ? FILE_NOT_FOUND_ERR
+                : (self.responseCode == 304 ? NOT_MODIFIED : CONNECTION_ERR);
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[command
createFileTransferError:errorCode AndSource:source AndTarget:target AndHttpStatus:self.responseCode
AndBody:downloadResponse]];
         }
     }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/18994228/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index d3e8520..d9e884e 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -60,6 +60,7 @@ FileTransferOperation.PENDING = 0;
 FileTransferOperation.DONE = 1;
 FileTransferOperation.CANCELLED = 2;
 
+var HTTP_E_STATUS_NOT_MODIFIED = -2145844944;
 
 module.exports = {
 
@@ -339,6 +340,8 @@ exec(win, fail, 'FileTransfer', 'upload',
                         // message property will be specified
                         if (error.message === 'Canceled') {
                             resolve(new FTErr(FTErr.ABORT_ERR, source, target, null, null,
error));
+                        } else if (error && error.number === HTTP_E_STATUS_NOT_MODIFIED)
{
+                            resolve(new FTErr(FTErr.NOT_MODIFIED_ERR, source, target, 304,
null, error));
                         } else {
                             // in the other way, try to get response property
                             var response = download.getResponseInformation();

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/18994228/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 083435f..fff1eef 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -503,7 +503,7 @@ exports.defineAutoTests = function () {
                         expect(error.http_status).toBe(404);
 
                         // wp8 does not make difference between 404 and unknown host
-                        if (isWp8) {
+                        if (isWP8) {
                             expect(error.code).toBe(FileTransferError.CONNECTION_ERR);
                         } else {
                             expect(error.code).toBe(FileTransferError.FILE_NOT_FOUND_ERR);
@@ -650,6 +650,30 @@ exports.defineAutoTests = function () {
                         transfer.download(fileURL, localPath, downloadWin, unexpectedCallbacks.httpFail);
                     }, unsupported, 'File', '_getLocalFilesystemPath', [internalFilePath]);
                 });
+
+                it('filetransfer.spec.31 should properly handle 304', function (done) {
+
+                    if(isWP8) {
+                        pending();
+                        return;
+                    }
+
+                    var imageURL = "http://apache.org/images/feather-small.gif";
+                    var lastModified = new Date();
+
+                    var downloadFail = function (error) {
+                        expect(error.http_status).toBe(304);
+                        expect(error.code).toBe(FileTransferError.NOT_MODIFIED_ERR);
+                        done();
+                    };
+
+                    transfer.download(imageURL, localFilePath, unexpectedCallbacks.httpWin,
downloadFail, null,
+                        {
+                            headers: {
+                                'If-Modified-Since': lastModified.toUTCString()
+                            }
+                        });
+                }, DOWNLOAD_TIMEOUT);
             });
 
             describe('upload', function() {


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


Mime
View raw message