瀏覽代碼

Added try-catches in upload test for XHR headers

adolfintel 6 年之前
父節點
當前提交
8ac704066e
共有 2 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      speedtest_worker.js
  2. 0 0
      speedtest_worker.min.js

+ 12 - 4
speedtest_worker.js

@@ -470,8 +470,12 @@ function ulTest(done) {
 						testStream(i, 0);
 					};
 					xhr[i].open("POST", settings.url_ul + url_sep(settings.url_ul) + "r=" + Math.random(), true); // random string to prevent caching
-					xhr[i].setRequestHeader("Content-Encoding", "identity"); // disable compression (some browsers may refuse it, but data is incompressible anyway)
-					xhr[i].setRequestHeader("Content-Type", "application/octet-stream");
+					try{
+						xhr[i].setRequestHeader("Content-Encoding", "identity"); // disable compression (some browsers may refuse it, but data is incompressible anyway)
+					}catch(e){}
+					try{
+						xhr[i].setRequestHeader("Content-Type", "application/octet-stream"); //force content-type to application/octet-stream in case the server misinterprets it
+					}catch(e){}
 					xhr[i].send(reqsmall);
 				} else {
 					// REGULAR version, no workaround
@@ -504,8 +508,12 @@ function ulTest(done) {
 					}.bind(this);
 					// send xhr
 					xhr[i].open("POST", settings.url_ul + url_sep(settings.url_ul) + "r=" + Math.random(), true); // random string to prevent caching
-					xhr[i].setRequestHeader("Content-Encoding", "identity"); // disable compression (some browsers may refuse it, but data is incompressible anyway)
-					xhr[i].setRequestHeader("Content-Type", "application/octet-stream");
+					try{
+						xhr[i].setRequestHeader("Content-Encoding", "identity"); // disable compression (some browsers may refuse it, but data is incompressible anyway)
+					}catch(e){}
+					try{
+						xhr[i].setRequestHeader("Content-Type", "application/octet-stream"); //force content-type to application/octet-stream in case the server misinterprets it
+					}catch(e){}
 					xhr[i].send(req);
 				}
 			}.bind(this),

File diff suppressed because it is too large
+ 0 - 0
speedtest_worker.min.js


Some files were not shown because too many files changed in this diff