diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp index 9d3b8fcc1e..f9dc714cd8 100644 --- a/indra/llmessage/llcorehttputil.cpp +++ b/indra/llmessage/llcorehttputil.cpp @@ -1307,3 +1307,81 @@ void HttpCoroutineAdapter::trivialPostCoro(std::string url, LLCore::HttpRequest: } // end namespace LLCoreHttpUtil +namespace FSCoreHttpUtil +{ +void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, completionCallback_t success, completionCallback_t failure) +{ + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoroRaw", policyId)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + + httpOpts->setWantHeaders(true); + + LL_INFOS("HttpCoroutineAdapter", "genericPostCoroRaw") << "Generic POST for " << url << LL_ENDL; + + LLSD result = httpAdapter->postRawAndSuspend(httpRequest, url, postData, httpOpts); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + // If a failure routine is provided do it. + if (failure) + { + failure(httpResults); + } + } + else + { + // If a success routine is provided do it. + if (success) + { + success(result); + } + } +} +void callbackHttpPostRaw(const std::string &url, LLCore::BufferArray::ptr_t postData, completionCallback_t success, completionCallback_t failure) +{ + LLCoros::instance().launch("HttpCoroutineAdapter::genericPostCoroRaw", + boost::bind(trivialPostCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, postData, success, failure)); +} + +void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, completionCallback_t success, completionCallback_t failure) +{ + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericGetCoro", policyId)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + + httpOpts->setWantHeaders(true); + + LL_INFOS("HttpCoroutineAdapter", "genericGetCoroRaw") << "Generic GET for " << url << LL_ENDL; + + LLSD result = httpAdapter->getRawAndSuspend(httpRequest, url, httpOpts); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + if (failure) + { + failure(httpResults); + } + } + else + { + if (success) + { + success(result); + } + } +} + +void callbackHttpGetRaw(const std::string &url, completionCallback_t success, completionCallback_t failure) +{ + LLCoros::instance().launch("HttpCoroutineAdapter::genericGetCoroRaw", + boost::bind(trivialGetCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, success, failure)); +} +} \ No newline at end of file diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h index 0ec17cda07..79322961de 100644 --- a/indra/llmessage/llcorehttputil.h +++ b/indra/llmessage/llcorehttputil.h @@ -677,4 +677,14 @@ private: } // end namespace LLCoreHttpUtil +namespace FSCoreHttpUtil +{ + typedef boost::function completionCallback_t; + + void callbackHttpPostRaw(const std::string &url, LLCore::BufferArray::ptr_t postData, completionCallback_t success = NULL, completionCallback_t failure = NULL); + void callbackHttpGetRaw(const std::string &url, completionCallback_t success = NULL, completionCallback_t failure = NULL); + + void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, completionCallback_t success, completionCallback_t failure); + void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, completionCallback_t success, completionCallback_t failure); +} #endif // LL_LLCOREHTTPUTIL_H