CB-10974 Cordova file transfer Content-Length header problem

Fixed iOS logic to not to include Content-Length when chunkedMode=true
Fixed Android logic preventing chunkedMode to be enabled for http uploads
Added tests for chunkedMode
Documented chunkedMode not supported on Windows
Documented Uploading of an empty file is not supported for chunkedMode=true and multipart=false for iOS, pended the corresponding test
This commit is contained in:
daserge
2016-04-13 17:24:57 +03:00
parent 6ad92c92ab
commit 9347606dd3
5 changed files with 102 additions and 5 deletions
+87
View File
@@ -1193,6 +1193,9 @@ exports.defineAutoTests = function () {
"CustomHeader2": ["CustomValue2", "CustomValue3"],
};
// http://whatheaders.com does not support Transfer-Encoding: chunked
this.uploadOptions.chunkedMode = false;
// NOTE: removing uploadOptions cause Android to timeout
this.transfer.upload(this.localFilePath, fileURL, uploadWin, uploadFail, this.uploadOptions);
}, UPLOAD_TIMEOUT);
@@ -1462,6 +1465,11 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.41 should not fail to upload a file using data: source uri when the data is empty (non-multipart)", function (done) {
if (isIos) {
// iOS does not support uploads of an empty file with __chunkedMode=true__ and `multipartMode=false`:
// request body will be empty in this case instead of 0\n\n.
pending();
}
var fileURL = SERVER + "/upload";
// Content-Type header disables multipart
@@ -1482,6 +1490,85 @@ exports.defineAutoTests = function () {
// NOTE: removing uploadOptions cause Android to timeout
this.transfer.upload(dataUri, fileURL, done, uploadFail, this.uploadOptions);
}, UPLOAD_TIMEOUT);
describe("chunkedMode handling", function() {
var testChunkedModeWin = function (uploadResult, specContext) {
var multipartModeEnabled = !(specContext.uploadOptions.headers && specContext.uploadOptions.headers["Content-Type"]);
var obj = null;
try {
obj = JSON.parse(uploadResult.response);
if (specContext.uploadOptions.chunkedMode) {
expect(obj["content-length"]).not.toBeDefined("Expected Content-Length not to be defined");
expect(obj["transfer-encoding"].toLowerCase()).toEqual("chunked");
} else {
expect(obj["content-length"]).toBeDefined("Expected Content-Length to be defined");
expect(obj["transfer-encoding"].toLowerCase()).not.toEqual("chunked");
}
if (multipartModeEnabled) {
expect(obj["content-type"].indexOf("multipart/form-data")).not.toBe(-1);
} else {
expect(obj["content-type"].indexOf("multipart/form-data")).toBe(-1);
}
} catch (e) {
expect(obj).not.toBeNull("returned data from server should be valid json");
}
};
var testChunkedModeBase = function(chunkedMode, multipart, done) {
var fileURL = SERVER + "/upload_echo_headers";
var specContext = this;
specContext.uploadOptions.chunkedMode = chunkedMode;
if (!multipart) {
// Content-Type header disables multipart
specContext.uploadOptions.headers = {
"Content-Type": "text/plain"
};
}
var uploadFail = function() {
unexpectedCallbacks.httpFail();
done();
};
// turn off the onprogress handler
this.transfer.onprogress = function () {};
// NOTE: removing uploadOptions cause Android to timeout
specContext.transfer.upload(specContext.localFilePath, fileURL, function (uploadResult) {
testChunkedModeWin(uploadResult, specContext);
done();
}, uploadFail, specContext.uploadOptions);
};
it("filetransfer.spec.42 chunkedMode=false, multipart=false", function (done) {
testChunkedModeBase.call(this, false, false, done);
}, UPLOAD_TIMEOUT);
it("filetransfer.spec.43 chunkedMode=true, multipart=false", function (done) {
if (isWindows) {
pending();
}
testChunkedModeBase.call(this, true, false, done);
}, UPLOAD_TIMEOUT);
it("filetransfer.spec.44 chunkedMode=false, multipart=true", function (done) {
testChunkedModeBase.call(this, false, true, done);
}, UPLOAD_TIMEOUT);
it("filetransfer.spec.45 chunkedMode=true, multipart=true", function (done) {
if (isWindows) {
pending();
}
testChunkedModeBase.call(this, true, true, done);
}, UPLOAD_TIMEOUT);
});
});
});
});