From 2afc380e1941aac21703b84c04db4ecf0675f297 Mon Sep 17 00:00:00 2001 From: EmanuelPeixoto Date: Thu, 23 Jul 2026 17:50:51 -0300 Subject: [PATCH] fix upload: check HTTP status in xhr.onload, expand IIS docs - speedtest_worker.js: moved HTTP status check from xhr.upload.onload (body sent, response may not be available) to xhr.onload (full HTTP transaction complete, xhr.status is reliable). - doc.md: added full IIS web.config example with maxAllowedContentLength. --- doc.md | 11 ++++++++++- speedtest_worker.js | 27 +++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/doc.md b/doc.md index 708241b..36c2c9c 100755 --- a/doc.md +++ b/doc.md @@ -72,7 +72,16 @@ Apache: LimitRequestBody 134217728 ``` -IIS: Set `maxAllowedContentLength` in `web.config`. +IIS: Add the following to `web.config` (value is in bytes): +```xml + + + + + + + +``` __Important:__ The speed test needs write permissions in the installation folder! diff --git a/speedtest_worker.js b/speedtest_worker.js index e5f8602..0dc0a43 100755 --- a/speedtest_worker.js +++ b/speedtest_worker.js @@ -502,20 +502,9 @@ function ulTest(done) { prevLoaded = event.loaded; }.bind(this); xhr[i].upload.onload = function() { - // check HTTP status - non-2xx means server rejected the request (e.g. 413 body too large) - if (xhr[i].status >= 200 && xhr[i].status < 300) { - // this stream sent all the garbage data, start again - tverb("ul stream finished " + i); - testStream(i, 0); - } else { - tverb("ul stream failed with HTTP " + xhr[i].status + " " + i); - if (settings.xhr_ignoreErrors === 0) failed = true; //abort - try { - xhr[i].abort(); - } catch (e) {} - delete xhr[i]; - if (settings.xhr_ignoreErrors === 1) testStream(i, 0); //restart stream - } + // this stream sent all the garbage data, start again + tverb("ul stream finished " + i); + testStream(i, 0); }.bind(this); xhr[i].upload.onerror = function() { tverb("ul stream failed " + i); @@ -526,6 +515,16 @@ function ulTest(done) { delete xhr[i]; if (settings.xhr_ignoreErrors === 1) testStream(i, 0); //restart stream }.bind(this); + xhr[i].onload = function() { + // check HTTP status after full response is available + if (xhr[i].status >= 200 && xhr[i].status < 300) return; + tverb("ul stream failed with HTTP " + xhr[i].status + " " + i); + if (settings.xhr_ignoreErrors === 0) failed = true; //abort + try { + xhr[i].abort(); + } catch (e) {} + delete xhr[i]; + }.bind(this); // send xhr xhr[i].open("POST", settings.url_ul + url_sep(settings.url_ul) + (settings.mpot ? "cors=true&" : "") + "r=" + Math.random(), true); // random string to prevent caching try {