summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorRider Linden <rider@lindenlab.com>2015-05-12 14:32:43 -0700
committerRider Linden <rider@lindenlab.com>2015-05-12 14:32:43 -0700
commit723834737dc8bdb608f73c5d7fe5bdebfdaa59e5 (patch)
tree306aba81f7624100c46aa98e19ff3fdd35d86264 /indra/llmessage
parentdcac06d7d2cf966915779256007e46a6fe6885de (diff)
Added trivial case GET and POST to the CoreHTTP Utils
converted llfloaterregioninfo to use coroutine's and new LLCore::HTTP
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llcorehttputil.cpp73
-rw-r--r--indra/llmessage/llcorehttputil.h12
2 files changed, 85 insertions, 0 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index a79bb62bb8..2ef9f59e2f 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -668,6 +668,7 @@ void HttpCoroutineAdapter::cleanState()
mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
}
+/*static*/
LLSD HttpCoroutineAdapter::buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
const std::string &url)
{
@@ -687,6 +688,7 @@ LLSD HttpCoroutineAdapter::buildImmediateErrorResult(const LLCore::HttpRequest::
return errorres;
}
+/*static*/
LLCore::HttpStatus HttpCoroutineAdapter::getStatusFromLLSD(const LLSD &httpResults)
{
LLCore::HttpStatus::type_enum_t type = static_cast<LLCore::HttpStatus::type_enum_t>(httpResults[HttpCoroutineAdapter::HTTP_RESULTS_TYPE].asInteger());
@@ -695,6 +697,77 @@ LLCore::HttpStatus HttpCoroutineAdapter::getStatusFromLLSD(const LLSD &httpResul
return LLCore::HttpStatus(type, code);
}
+/*static*/
+void HttpCoroutineAdapter::genericHttpGet(const std::string &url, const std::string &success, const std::string &failure)
+{
+ LLCoros::instance().launch("HttpCoroutineAdapter::genericGetCoro",
+ boost::bind(&HttpCoroutineAdapter::genericGetCoro, _1, url, success, failure));
+}
+
+/*static*/
+void HttpCoroutineAdapter::genericGetCoro(LLCoros::self& self, std::string &url, std::string success, std::string failure)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericGetCoro", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+
+ LL_INFOS("HttpCoroutineAdapter", "genericGetCoro") << "Generic GET for " << url << LL_ENDL;
+
+ LLSD result = httpAdapter->getAndYield(self, httpRequest, url);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ if (status)
+ {
+ LL_INFOS("HttpCoroutineAdapter", "genericGetCoro") << "Success for " << url << std::endl <<
+ "Message: '" << success << "'" << LL_ENDL;
+ }
+ else
+ {
+ LL_WARNS("HttpCoroutineAdapter", "genericGetCoro") << "Failure for " << url << std::endl <<
+ "Message: '" << failure << "'" << std::endl <<
+ "Status: " << status.toTerseString() << ": " << status.getMessage() << LL_ENDL;
+ }
+}
+
+/*static*/
+void HttpCoroutineAdapter::genericHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure)
+{
+ LLCoros::instance().launch("HttpCoroutineAdapter::genericPostCoro",
+ boost::bind(&HttpCoroutineAdapter::genericPostCoro, _1, url, postData, success, failure));
+}
+
+/*static*/
+void HttpCoroutineAdapter::genericPostCoro(LLCoros::self& self, std::string &url, LLSD postData, std::string success, std::string failure)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoro", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+
+ LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL;
+
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, url, postData);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ if (status)
+ {
+ LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Success for " << url << std::endl <<
+ "Message: '" << success << "'" << LL_ENDL;
+ }
+ else
+ {
+ LL_WARNS("HttpCoroutineAdapter", "genericPostCoro") << "Failure for " << url << std::endl <<
+ "Message: '" << failure << "'" << std::endl <<
+ "Status: " << status.toTerseString() << ": " << status.getMessage() << LL_ENDL;
+ }
+}
+
+
} // end namespace LLCoreHttpUtil
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index e8e5f1b1aa..7d60bfbbaf 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -387,8 +387,17 @@ public:
///
void cancelYieldingOperation();
+
static LLCore::HttpStatus getStatusFromLLSD(const LLSD &httpResults);
+ /// Generic Get and post routines for HTTP via coroutines.
+ /// These static methods do all required setup for the GET or POST operation.
+ /// When the operation completes successfully they will put the success message in the log at INFO level,
+ /// If the operation fails the failure message is written to the log at WARN level.
+ ///
+ static void genericHttpGet(const std::string &url, const std::string &success = std::string(), const std::string &failure = std::string());
+ static void genericHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure);
+
private:
static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request, const std::string &url);
@@ -419,6 +428,9 @@ private:
const std::string & url, LLCore::HttpOptions::ptr_t &options,
LLCore::HttpHeaders::ptr_t &headers, HttpCoroHandler::ptr_t &handler);
+ static void genericGetCoro(LLCoros::self& self, std::string &url, std::string success, std::string failure);
+ static void genericPostCoro(LLCoros::self& self, std::string &url, LLSD postData, std::string success, std::string failure);
+
std::string mAdapterName;
LLCore::HttpRequest::priority_t mPriority;
LLCore::HttpRequest::policy_t mPolicyId;