From 8b8ed384d5f974424a8bdce2c616b0f18b36bad6 Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Sat, 26 May 2018 00:33:39 -0700 Subject: [PATCH 1/4] Added check for edge15+ and emptying out content type w/ use cases --- client/js/s3/s3.xhr.upload.handler.js | 4 ++-- client/js/util.js | 11 +++++++++++ test/unit/s3/chunked-uploads.js | 25 +++++++++++++++++++------ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/js/s3/s3.xhr.upload.handler.js b/client/js/s3/s3.xhr.upload.handler.js index 41299ac1d..5119fafdb 100755 --- a/client/js/s3/s3.xhr.upload.handler.js +++ b/client/js/s3/s3.xhr.upload.handler.js @@ -124,8 +124,8 @@ qq.s3.XhrUploadHandler = function(spec, proxy) { xhr.setRequestHeader(name, val); }); - // Workaround for IE Edge - if (!hasContentType) { + // Do not set this for safari 9 + if (qq.edge15() && !hasContentType) { xhr.setRequestHeader("Content-Type", ""); } diff --git a/client/js/util.js b/client/js/util.js index f6d5f109c..7e9479554 100644 --- a/client/js/util.js +++ b/client/js/util.js @@ -542,6 +542,17 @@ var qq = function(element) { return navigator.userAgent.indexOf("Edge") >= 0; }; + qq.edge15 = function() { + var edge = navigator.userAgent.indexOf('Edge/'); + var edge_version = 0; + + if (edge > 0) { + edge_version = parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); + } + + return edge && edge_version >= 15; + }; + qq.safari = function() { return navigator.vendor !== undefined && navigator.vendor.indexOf("Apple") !== -1; }; diff --git a/test/unit/s3/chunked-uploads.js b/test/unit/s3/chunked-uploads.js index 14664c53a..515401446 100644 --- a/test/unit/s3/chunked-uploads.js +++ b/test/unit/s3/chunked-uploads.js @@ -10,6 +10,7 @@ if (qqtest.canDownloadFileAsBlob) { testAccessKey = "testAccessKey", expectedFileSize = 3266, expectedChunks = 2, + isEdge15 = qq.edge15(), chunkSize = Math.round(expectedFileSize / expectedChunks), typicalChunkingOption = { enabled: true, @@ -161,7 +162,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } var authParts = uploadPartRequest.requestHeaders.Authorization.split(";"); assert.equal(authParts.length, 3); @@ -191,7 +194,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15()) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } var authParts = uploadPartRequest.requestHeaders.Authorization.split(";"); assert.equal(authParts.length, 3); @@ -348,7 +353,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } assert.equal(uploadPartRequest.requestHeaders.Authorization, "AWS " + testAccessKey + ":thesignature"); uploadPartRequest.respond(200, {ETag: "etag1"}, null); @@ -372,7 +379,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } assert.equal(uploadPartRequest.requestHeaders.Authorization, "AWS " + testAccessKey + ":thesignature"); uploadPartRequest.respond(200, {ETag: "etag2"}, null); @@ -811,7 +820,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=1&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } assert.equal(uploadPartRequest.requestHeaders.Authorization.indexOf("AWS " + testAccessKey + ":"), 0, "Upload part 1 request Authorization header is invalid"); uploadPartRequest.respond(200, {ETag: "etag1"}, null); @@ -823,7 +834,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + if (isEdge15) { + assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); + } assert.equal(uploadPartRequest.requestHeaders.Authorization.indexOf("AWS " + testAccessKey + ":"), 0, "Upload part 2 request Authorization header is invalid"); uploadPartRequest.respond(200, {ETag: "etag2"}, null); From 5e19c413b4d390dda100e800952ce35ae8c140eb Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Sat, 26 May 2018 00:36:30 -0700 Subject: [PATCH 2/4] Corrections for JSCS and comments --- client/js/s3/s3.xhr.upload.handler.js | 2 +- client/js/util.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/js/s3/s3.xhr.upload.handler.js b/client/js/s3/s3.xhr.upload.handler.js index 5119fafdb..d70b5abb6 100755 --- a/client/js/s3/s3.xhr.upload.handler.js +++ b/client/js/s3/s3.xhr.upload.handler.js @@ -124,7 +124,7 @@ qq.s3.XhrUploadHandler = function(spec, proxy) { xhr.setRequestHeader(name, val); }); - // Do not set this for safari 9 + // Set this only for edge 15 or higher if (qq.edge15() && !hasContentType) { xhr.setRequestHeader("Content-Type", ""); } diff --git a/client/js/util.js b/client/js/util.js index 7e9479554..168d2e5dd 100644 --- a/client/js/util.js +++ b/client/js/util.js @@ -543,14 +543,14 @@ var qq = function(element) { }; qq.edge15 = function() { - var edge = navigator.userAgent.indexOf('Edge/'); - var edge_version = 0; + var edge = navigator.userAgent.indexOf("Edge/"); + var edgeVersion = 0; if (edge > 0) { - edge_version = parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); + edgeVersion = parseInt(ua.substring(edge + 5, ua.indexOf(".", edge)), 10); } - return edge && edge_version >= 15; + return edge && edgeVersion >= 15; }; qq.safari = function() { From 27bb7b09fdd3f26b7f43bc5d1803f6054847dae3 Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Sat, 26 May 2018 01:33:19 -0700 Subject: [PATCH 3/4] Tweaks and fixes for user agent etc --- client/js/util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/js/util.js b/client/js/util.js index 168d2e5dd..f024d832e 100644 --- a/client/js/util.js +++ b/client/js/util.js @@ -543,7 +543,8 @@ var qq = function(element) { }; qq.edge15 = function() { - var edge = navigator.userAgent.indexOf("Edge/"); + var ua = navigator.userAgent; + var edge = ua.indexOf("Edge/"); var edgeVersion = 0; if (edge > 0) { From 868a2120768e6e8f7446533a4e5d716ef927722b Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Sat, 26 May 2018 01:40:35 -0700 Subject: [PATCH 4/4] Corrected typo --- test/unit/s3/chunked-uploads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/s3/chunked-uploads.js b/test/unit/s3/chunked-uploads.js index 515401446..60ec05cc6 100644 --- a/test/unit/s3/chunked-uploads.js +++ b/test/unit/s3/chunked-uploads.js @@ -194,7 +194,7 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(uploadPartRequest.url, testS3Endpoint + "/" + uploader.getKey(0) + "?partNumber=2&uploadId=123"); assert.ok(uploadPartRequest.requestHeaders["x-amz-date"]); - if (isEdge15()) { + if (isEdge15) { assert.equal(uploadPartRequest.requestHeaders["Content-Type"], ""); }