Mercurial > hg > orthanc-stone
diff Framework/Oracle/WebAssemblyOracle.cpp @ 841:266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
in WebAssemblyOracle + support for LookupTableTextureSceneLayer in OpenGL (NOT
using shaders!) (2 new files) + a few small non-functional changes
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 11 Jun 2019 15:41:21 +0200 |
parents | d71cf8504159 |
children | 67f9c27214c5 |
line wrap: on
line diff
--- a/Framework/Oracle/WebAssemblyOracle.cpp Sun Jun 09 18:47:34 2019 +0200 +++ b/Framework/Oracle/WebAssemblyOracle.cpp Tue Jun 11 15:41:21 2019 +0200 @@ -284,7 +284,12 @@ void SetBody(std::string& body /* will be swapped */) { + if (body != "") + { + LOG(ERROR) << "Setting non-empty body. body size = " << body.size() << " body = " << body; + } body_.swap(body); + LOG(ERROR) << "After setting non-empty body. body_ size = " << body_.size() << " body_ = " << body_; } void SetHttpHeaders(const HttpHeaders& headers) @@ -365,19 +370,32 @@ attr.requestHeaders = &headers[0]; + char* requestData = NULL; if (!body_.empty()) + requestData = reinterpret_cast<char*>(malloc(body_.size())); + + try { - attr.requestDataSize = body_.size(); - attr.requestData = body_.c_str(); - } + if (!body_.empty()) + { + memcpy(requestData, &(body_[0]), body_.size()); + attr.requestDataSize = body_.size(); + attr.requestData = requestData; + } + attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); - // Must be the last call to prevent memory leak on error - attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); - emscripten_fetch(&attr, uri_.c_str()); - } + // Must be the last call to prevent memory leak on error + emscripten_fetch(&attr, uri_.c_str()); + } + catch(...) + { + if(requestData != NULL) + free(requestData); + throw; + } + } }; - void WebAssemblyOracle::Execute(const IObserver& receiver, OrthancRestApiCommand* command) { @@ -388,14 +406,14 @@ fetch.SetHttpHeaders(command->GetHttpHeaders()); fetch.SetTimeout(command->GetTimeout()); - if (command->GetMethod() == Orthanc::HttpMethod_Put || + if (command->GetMethod() == Orthanc::HttpMethod_Post || command->GetMethod() == Orthanc::HttpMethod_Put) { std::string body; command->SwapBody(body); fetch.SetBody(body); } - + fetch.Execute(); }