aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llhttpclient.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:54 -0500
committerJacek Antonelli2008-08-15 23:44:54 -0500
commitb2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch)
tree3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llmessage/llhttpclient.cpp
parentSecond Life viewer sources 1.14.0.1 (diff)
downloadmeta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz
Second Life viewer sources 1.15.0.2
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llhttpclient.cpp65
1 files changed, 45 insertions, 20 deletions
diff --git a/linden/indra/llmessage/llhttpclient.cpp b/linden/indra/llmessage/llhttpclient.cpp
index 3755ae0..1d38a13 100644
--- a/linden/indra/llmessage/llhttpclient.cpp
+++ b/linden/indra/llmessage/llhttpclient.cpp
@@ -4,6 +4,7 @@
4 * 4 *
5 * Copyright (c) 2006-2007, Linden Research, Inc. 5 * Copyright (c) 2006-2007, Linden Research, Inc.
6 * 6 *
7 * Second Life Viewer Source Code
7 * The source code in this file ("Source Code") is provided by Linden Lab 8 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0 9 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement 10 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -37,9 +38,10 @@
37#include "llvfile.h" 38#include "llvfile.h"
38#include "llvfs.h" 39#include "llvfs.h"
39 40
41#include "message.h"
40#include <curl/curl.h> 42#include <curl/curl.h>
41 43
42static const F32 HTTP_REQUEST_EXPIRY_SECS = 60.0f; 44const F32 HTTP_REQUEST_EXPIRY_SECS = 60.0f;
43 45
44static std::string gCABundle; 46static std::string gCABundle;
45 47
@@ -111,6 +113,14 @@ namespace
111 if (200 <= mStatus && mStatus < 300) 113 if (200 <= mStatus && mStatus < 300)
112 { 114 {
113 LLSDSerialize::fromXML(content, istr); 115 LLSDSerialize::fromXML(content, istr);
116/*
117 const S32 parseError = -1;
118 if(LLSDSerialize::fromXML(content, istr) == parseError)
119 {
120 mStatus = 498;
121 mReason = "Client Parse Error";
122 }
123*/
114 } 124 }
115 125
116 if (mResponder.get()) 126 if (mResponder.get())
@@ -233,7 +243,7 @@ namespace
233} 243}
234 244
235static void request(const std::string& url, LLURLRequest::ERequestAction method, 245static void request(const std::string& url, LLURLRequest::ERequestAction method,
236 Injector* body_injector, LLHTTPClient::ResponderPtr responder) 246 Injector* body_injector, LLHTTPClient::ResponderPtr responder, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS)
237{ 247{
238 if (!LLHTTPClient::hasPump()) 248 if (!LLHTTPClient::hasPump())
239 { 249 {
@@ -251,19 +261,26 @@ static void request(const std::string& url, LLURLRequest::ERequestAction method,
251 } 261 }
252 req->setCallback(new LLHTTPClientURLAdaptor(responder)); 262 req->setCallback(new LLHTTPClientURLAdaptor(responder));
253 263
264 if (method == LLURLRequest::HTTP_POST && gMessageSystem) {
265 req->addHeader(llformat("X-SecondLife-UDP-Listen-Port: %d",
266 gMessageSystem->mPort).c_str());
267 }
268
254 if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST) 269 if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST)
255 { 270 {
256 req->addHeader(llformat("Content-Type: %s", body_injector->contentType()).c_str()); 271 req->addHeader(llformat("Content-Type: %s",
257 chain.push_back(LLIOPipe::ptr_t(body_injector)); 272 body_injector->contentType()).c_str());
273
274 chain.push_back(LLIOPipe::ptr_t(body_injector));
258 } 275 }
259 chain.push_back(LLIOPipe::ptr_t(req)); 276 chain.push_back(LLIOPipe::ptr_t(req));
260 277
261 theClientPump->addChain(chain, HTTP_REQUEST_EXPIRY_SECS); 278 theClientPump->addChain(chain, timeout);
262} 279}
263 280
264void LLHTTPClient::get(const std::string& url, ResponderPtr responder) 281void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const F32 timeout)
265{ 282{
266 request(url, LLURLRequest::HTTP_GET, NULL, responder); 283 request(url, LLURLRequest::HTTP_GET, NULL, responder, timeout);
267} 284}
268 285
269// A simple class for managing data returned from a curl http request. 286// A simple class for managing data returned from a curl http request.
@@ -312,6 +329,14 @@ LLSD LLHTTPClient::blockingGet(const std::string& url)
312 329
313 LLHTTPBuffer http_buffer; 330 LLHTTPBuffer http_buffer;
314 331
332 // Without this timeout, blockingGet() calls have been observed to take
333 // up to 90 seconds to complete. Users of blockingGet() already must
334 // check the HTTP return code for validity, so this will not introduce
335 // new errors. A 5 second timeout will succeed > 95% of the time (and
336 // probably > 99% of the time) based on my statistics. JC
337 curl_easy_setopt(curlp, CURLOPT_NOSIGNAL, 1); // don't use SIGALRM for timeouts
338 curl_easy_setopt(curlp, CURLOPT_TIMEOUT, 5); // seconds
339
315 curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, LLHTTPBuffer::curl_write); 340 curl_easy_setopt(curlp, CURLOPT_WRITEFUNCTION, LLHTTPBuffer::curl_write);
316 curl_easy_setopt(curlp, CURLOPT_WRITEDATA, &http_buffer); 341 curl_easy_setopt(curlp, CURLOPT_WRITEDATA, &http_buffer);
317 curl_easy_setopt(curlp, CURLOPT_URL, url.c_str()); 342 curl_easy_setopt(curlp, CURLOPT_URL, url.c_str());
@@ -344,36 +369,36 @@ LLSD LLHTTPClient::blockingGet(const std::string& url)
344 return response; 369 return response;
345} 370}
346 371
347void LLHTTPClient::put(const std::string& url, const LLSD& body, ResponderPtr responder) 372void LLHTTPClient::put(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout)
348{ 373{
349 request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder); 374 request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, timeout);
350} 375}
351 376
352void LLHTTPClient::post(const std::string& url, const LLSD& body, ResponderPtr responder) 377void LLHTTPClient::post(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout)
353{ 378{
354 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder); 379 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout);
355} 380}
356 381
357void LLHTTPClient::post(const std::string& url, const U8* data, S32 size, ResponderPtr responder) 382void LLHTTPClient::post(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout)
358{ 383{
359 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder); 384 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout);
360} 385}
361 386
362void LLHTTPClient::del(const std::string& url, ResponderPtr responder) 387void LLHTTPClient::del(const std::string& url, ResponderPtr responder, const F32 timeout)
363{ 388{
364 request(url, LLURLRequest::HTTP_DELETE, NULL, responder); 389 request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout);
365} 390}
366 391
367#if 1 392#if 1
368void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder) 393void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder, const F32 timeout)
369{ 394{
370 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder); 395 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout);
371} 396}
372 397
373void LLHTTPClient::postFile(const std::string& url, const LLUUID& uuid, 398void LLHTTPClient::postFile(const std::string& url, const LLUUID& uuid,
374 LLAssetType::EType asset_type, ResponderPtr responder) 399 LLAssetType::EType asset_type, ResponderPtr responder, const F32 timeout)
375{ 400{
376 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder); 401 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout);
377} 402}
378#endif 403#endif
379 404
@@ -401,7 +426,7 @@ namespace boost
401 426
402 void intrusive_ptr_release(LLHTTPClient::Responder* p) 427 void intrusive_ptr_release(LLHTTPClient::Responder* p)
403 { 428 {
404 if(0 == --p->mReferenceCount) 429 if(p && 0 == --p->mReferenceCount)
405 { 430 {
406 delete p; 431 delete p;
407 } 432 }