summaryrefslogtreecommitdiff
path: root/indra/llmessage/llhttpclient.cpp
diff options
context:
space:
mode:
authorKelly Washington <kelly@lindenlab.com>2007-03-05 19:08:01 +0000
committerKelly Washington <kelly@lindenlab.com>2007-03-05 19:08:01 +0000
commit437882ca3ba259911d02889621afa334ae1c76db (patch)
tree14de9c7f39dea5dcde3c2265a4a5dd2c8c5fc3c6 /indra/llmessage/llhttpclient.cpp
parent7e99d870f2e7e5de48a59c7442b12b2f24ecb211 (diff)
merge r58577:58578 Branch_1-13-3 to release
Diffstat (limited to 'indra/llmessage/llhttpclient.cpp')
-rw-r--r--indra/llmessage/llhttpclient.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp
index 7d51b6c722..d83308d082 100644
--- a/indra/llmessage/llhttpclient.cpp
+++ b/indra/llmessage/llhttpclient.cpp
@@ -18,6 +18,8 @@
#include "llvfile.h"
#include "llvfs.h"
+#include <curl/curl.h>
+
static const F32 HTTP_REQUEST_EXPIRY_SECS = 60.0f;
static std::string gCABundle;
@@ -224,6 +226,71 @@ void LLHTTPClient::get(const std::string& url, ResponderPtr responder)
request(url, LLURLRequest::HTTP_GET, NULL, responder);
}
+// A simple class for managing data returned from a curl http request.
+class LLHTTPBuffer
+{
+public:
+ LLHTTPBuffer() { }
+
+ static size_t curl_write( void *ptr, size_t size, size_t nmemb, void *user_data)
+ {
+ LLHTTPBuffer* self = (LLHTTPBuffer*)user_data;
+
+ size_t bytes = (size * nmemb);
+ self->mBuffer.append((char*)ptr,bytes);
+ return nmemb;
+ }
+
+ LLSD asLLSD()
+ {
+ LLSD content;
+ std::istringstream istr(mBuffer);
+ LLSDSerialize::fromXML(content, istr);
+ return content;
+ }
+
+private:
+ std::string mBuffer;
+};
+
+// This call is blocking! This is probably usually bad. :(
+LLSD LLHTTPClient::blockingGet(const std::string& url)
+{
+ llinfos << "blockingGet of " << url << llendl;
+
+ // Returns an LLSD map: {status: integer, body: map}
+ char curl_error_buffer[CURL_ERROR_SIZE];
+ CURL* curlp = curl_easy_init();
+
+ LLHTTPBuffer http_buffer;
+
+ curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, LLHTTPBuffer::curl_write);
+ curl_easy_setopt(curlp, CURLOPT_WRITEDATA, &http_buffer);
+ curl_easy_setopt(curlp, CURLOPT_URL, url.c_str());
+ curl_easy_setopt(curlp, CURLOPT_ERRORBUFFER, curl_error_buffer);
+ curl_easy_setopt(curlp, CURLOPT_FAILONERROR, 1);
+
+ LLSD response = LLSD::emptyMap();
+
+ S32 curl_success = curl_easy_perform(curlp);
+
+ S32 http_status = 499;
+ curl_easy_getinfo(curlp,CURLINFO_RESPONSE_CODE, &http_status);
+
+ if (curl_success != 0
+ && http_status != 404) // We expect 404s, don't spam for them.
+ {
+ llwarns << "CURL ERROR: " << curl_error_buffer << llendl;
+ }
+
+ response["status"] = http_status;
+ response["body"] = http_buffer.asLLSD();
+
+ curl_easy_cleanup(curlp);
+
+ return response;
+}
+
void LLHTTPClient::put(const std::string& url, const LLSD& body, ResponderPtr responder)
{
request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder);