From ad2fc3056bf4af72a235e10e71bc0d0ea5fc5ee0 Mon Sep 17 00:00:00 2001 From: pixelherodev Date: Mon, 8 Oct 2018 06:31:20 -0400 Subject: [PATCH] Get error code on failure to load file for emscripten httpfs (#316) ...uses emscripten_wget2 function to get an actual error code back from failed HTTP requests --- .../Modules/HttpFS/private/emsc/emscURLLoader.cc | 16 +++++++--------- code/Modules/HttpFS/private/emsc/emscURLLoader.h | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/code/Modules/HttpFS/private/emsc/emscURLLoader.cc b/code/Modules/HttpFS/private/emsc/emscURLLoader.cc index bf2d42e1b..4882e9f02 100644 --- a/code/Modules/HttpFS/private/emsc/emscURLLoader.cc +++ b/code/Modules/HttpFS/private/emsc/emscURLLoader.cc @@ -33,13 +33,14 @@ emscURLLoader::startRequest(const Ptr& req) { // start the asynchronous XHR // NOTE: we can only load from our own HTTP server, so the host part of // the URL is completely irrelevant... - String urlPath = req->Url.PathToEnd(); - emscripten_async_wget_data(urlPath.AsCStr(), (void*) reqPtr, emscURLLoader::onLoaded, emscURLLoader::onFailed); + StringBuilder urlPath = "/"; + urlPath.Append(req->Url.PathToEnd()); + emscripten_async_wget2_data(urlPath.AsCStr(), "GET", NULL, (void*) reqPtr, true, emscURLLoader::onLoaded, emscURLLoader::onFailed, NULL); } //------------------------------------------------------------------------------ void -emscURLLoader::onLoaded(void* userData, void* buffer, int size) { +emscURLLoader::onLoaded(unsigned int handle, void* userData, void* buffer, unsigned int size) { o_assert(0 != userData); o_assert(0 != buffer); o_assert(size > 0); @@ -53,18 +54,15 @@ emscURLLoader::onLoaded(void* userData, void* buffer, int size) { //------------------------------------------------------------------------------ void -emscURLLoader::onFailed(void* userData) { +emscURLLoader::onFailed(unsigned int handle, void* userData, int errorCode, const char *statusDescription) { o_assert(0 != userData); // user data is a HTTPRequest ptr, put it back into a smart pointer Ptr req((IORead*)userData); req->release(); - Log::Dbg("emscURLLoader::onFailed(url=%s)\n", req->Url.AsCStr()); + Log::Dbg("emscURLLoader::onFailed(url=%s, code=%d, message=%s)\n", req->Url.AsCStr(), errorCode, statusDescription); - // hmm we don't know why it failed, so make something up, we should definitely - // fix this somehow (looks like the wget2 functions also pass a HTTP status code) - const IOStatus::Code ioStatus = IOStatus::NotFound; - req->Status = ioStatus; + req->Status = (IOStatus::Code)errorCode; req->Handled = true; } diff --git a/code/Modules/HttpFS/private/emsc/emscURLLoader.h b/code/Modules/HttpFS/private/emsc/emscURLLoader.h index eb3f4066a..770377fff 100644 --- a/code/Modules/HttpFS/private/emsc/emscURLLoader.h +++ b/code/Modules/HttpFS/private/emsc/emscURLLoader.h @@ -19,9 +19,9 @@ class emscURLLoader : public baseURLLoader { /// start the next, called from doWork void startRequest(const Ptr& req); /// success callback - static void onLoaded(void* userData, void* buffer, int size); + static void onLoaded(unsigned int handle, void* userData, void* buffer, unsigned int size); /// failure callback - static void onFailed(void* userData); + static void onFailed(unsigned int handle, void* userData, int errorCode, const char *statusDescription); }; } // namespace _priv