diff --git a/doc/compile-fixes.md b/doc/compile-fixes.md index b860d2ec2..cc5a7b81e 100644 --- a/doc/compile-fixes.md +++ b/doc/compile-fixes.md @@ -65,24 +65,3 @@ and change to ``` eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, { useCapture: eventHandler.useCapture, passive: false }); ``` - -#### Texture pack confirm dialog always shows *Download size: Determining*.. -Unfortunately emscripten doesn't store content-length for HEAD http requests. This can be fixed. - -First you need to find at what offset emscripten stores content-length. Look for something like: -``` -xhr.onprogress = function(e) { -... - Fetch.setu64(fetch + 32, e.total); -``` -then look for -``` -xhr.onload = function(e) { -... -``` -and finally change that to -``` -xhr.onload = function(e) { - Fetch.setu64(fetch + 32, e.total); -... -``` diff --git a/readme.md b/readme.md index f13521f72..f2cfb63a4 100644 --- a/readme.md +++ b/readme.md @@ -124,7 +124,7 @@ NOTE: You have to change entry->d_type == DT_DIR to Directory_Exists(&path) (TOD #### Web -```emcc *.c -s FETCH=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip``` +```emcc *.c -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip``` The generated javascript file has some issues. [See here for how to fix](doc/compile-fixes.md#webclient-patches) diff --git a/src/Http.c b/src/Http.c index e07363499..e626cf2be 100644 --- a/src/Http.c +++ b/src/Http.c @@ -354,17 +354,26 @@ static void Http_DownloadAsync(struct HttpRequest* req) { var xhr = new XMLHttpRequest(); xhr.open(reqMethod, url); xhr.responseType = 'arraybuffer'; + + var getContentLength = function(e) { + if (e.total) return e.total; + + try { + var len = xhr.getResponseHeader('Content-Length'); + return parseInt(len, 10); + } catch (ex) { return 0; } + }; xhr.onload = function(e) { var src = new Uint8Array(xhr.response); var len = src.byteLength; var data = _malloc(len); HEAPU8.set(src, data); - onFinished(data, len || e.total, xhr.status); + onFinished(data, len || getContentLength(e), xhr.status); }; - xhr.onerror = function(e) { onFinished(0, 0, xhr.status); }; - xhr.ontimeout = function(e) { onFinished(0, 0, xhr.status); }; - xhr.onprogress = function(e) { onProgress(e.loaded, e.total); }; + xhr.onerror = function(e) { onFinished(0, 0, xhr.status); }; + xhr.ontimeout = function(e) { onFinished(0, 0, xhr.status); }; + xhr.onprogress = function(e) { onProgress(e.loaded, e.total); }; try { xhr.send(); } catch (e) { onFinished(0, 0, 0); } }, urlStr, req->requestType, OnFinishedAsync, OnUpdateProgress);