aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llhttpclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/llhttpclient.cpp')
-rw-r--r--linden/indra/llmessage/llhttpclient.cpp112
1 files changed, 85 insertions, 27 deletions
diff --git a/linden/indra/llmessage/llhttpclient.cpp b/linden/indra/llmessage/llhttpclient.cpp
index ef163fa..a07f379 100644
--- a/linden/indra/llmessage/llhttpclient.cpp
+++ b/linden/indra/llmessage/llhttpclient.cpp
@@ -106,7 +106,7 @@ namespace
106 LLSDInjector(const LLSD& sd) : mSD(sd) {} 106 LLSDInjector(const LLSD& sd) : mSD(sd) {}
107 virtual ~LLSDInjector() {} 107 virtual ~LLSDInjector() {}
108 108
109 const char* contentType() { return "application/xml"; } 109 const char* contentType() { return "application/llsd+xml"; }
110 110
111 virtual EStatus process_impl(const LLChannelDescriptors& channels, 111 virtual EStatus process_impl(const LLChannelDescriptors& channels,
112 buffer_ptr_t& buffer, bool& eos, LLSD& context, LLPumpIO* pump) 112 buffer_ptr_t& buffer, bool& eos, LLSD& context, LLPumpIO* pump)
@@ -160,9 +160,10 @@ namespace
160 fstream.seekg(0, std::ios::end); 160 fstream.seekg(0, std::ios::end);
161 U32 fileSize = fstream.tellg(); 161 U32 fileSize = fstream.tellg();
162 fstream.seekg(0, std::ios::beg); 162 fstream.seekg(0, std::ios::beg);
163 std::vector<char> fileBuffer(fileSize); 163 char* fileBuffer;
164 fstream.read(&fileBuffer[0], fileSize); 164 fileBuffer = new char [fileSize];
165 ostream.write(&fileBuffer[0], fileSize); 165 fstream.read(fileBuffer, fileSize);
166 ostream.write(fileBuffer, fileSize);
166 fstream.close(); 167 fstream.close();
167 eos = true; 168 eos = true;
168 return STATUS_DONE; 169 return STATUS_DONE;
@@ -189,9 +190,10 @@ namespace
189 190
190 LLVFile vfile(gVFS, mUUID, mAssetType, LLVFile::READ); 191 LLVFile vfile(gVFS, mUUID, mAssetType, LLVFile::READ);
191 S32 fileSize = vfile.getSize(); 192 S32 fileSize = vfile.getSize();
192 std::vector<U8> fileBuffer(fileSize); 193 U8* fileBuffer;
193 vfile.read(&fileBuffer[0], fileSize); 194 fileBuffer = new U8 [fileSize];
194 ostream.write((char*)&fileBuffer[0], fileSize); 195 vfile.read(fileBuffer, fileSize);
196 ostream.write((char*)fileBuffer, fileSize);
195 eos = true; 197 eos = true;
196 return STATUS_DONE; 198 return STATUS_DONE;
197 } 199 }
@@ -236,7 +238,8 @@ static void request(
236 //the Pragma header it so gratuitously inserts 238 //the Pragma header it so gratuitously inserts
237 //Before inserting the header, force libcurl 239 //Before inserting the header, force libcurl
238 //to not use the proxy (read: llurlrequest.cpp) 240 //to not use the proxy (read: llurlrequest.cpp)
239 if ((iter->first == "Pragma") && (iter->second.asString() == "")) 241 static const std::string PRAGMA("Pragma");
242 if ((iter->first == PRAGMA) && (iter->second.asString().empty()))
240 { 243 {
241 req->useProxy(false); 244 req->useProxy(false);
242 } 245 }
@@ -245,6 +248,19 @@ static void request(
245 req->addHeader(header.str().c_str()); 248 req->addHeader(header.str().c_str());
246 } 249 }
247 } 250 }
251
252 // Check to see if we have already set Accept or not. If no one
253 // set it, set it to application/llsd+xml since that's what we
254 // almost always want.
255 if( method != LLURLRequest::HTTP_PUT && method != LLURLRequest::HTTP_POST )
256 {
257 static const std::string ACCEPT("Accept");
258 if(!headers.has(ACCEPT))
259 {
260 req->addHeader("Accept: application/llsd+xml");
261 }
262 }
263
248 req->setCallback(new LLHTTPClientURLAdaptor(responder)); 264 req->setCallback(new LLHTTPClientURLAdaptor(responder));
249 265
250 if (method == LLURLRequest::HTTP_POST && gMessageSystem) 266 if (method == LLURLRequest::HTTP_POST && gMessageSystem)
@@ -252,12 +268,22 @@ static void request(
252 req->addHeader(llformat("X-SecondLife-UDP-Listen-Port: %d", 268 req->addHeader(llformat("X-SecondLife-UDP-Listen-Port: %d",
253 gMessageSystem->mPort).c_str()); 269 gMessageSystem->mPort).c_str());
254 } 270 }
255 271
256 if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST) 272 if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST)
257 { 273 {
258 req->addHeader(llformat("Content-Type: %s", 274 static const std::string CONTENT_TYPE("Content-Type");
259 body_injector->contentType()).c_str()); 275 if(!headers.has(CONTENT_TYPE))
260 276 {
277 // If the Content-Type header was passed in, it has
278 // already been added as a header through req->addHeader
279 // in the loop above. We defer to the caller's wisdom, but
280 // if they did not specify a Content-Type, then ask the
281 // injector.
282 req->addHeader(
283 llformat(
284 "Content-Type: %s",
285 body_injector->contentType()).c_str());
286 }
261 chain.push_back(LLIOPipe::ptr_t(body_injector)); 287 chain.push_back(LLIOPipe::ptr_t(body_injector));
262 } 288 }
263 289
@@ -284,9 +310,13 @@ void LLHTTPClient::getByteRange(
284 request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers); 310 request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers);
285} 311}
286 312
287void LLHTTPClient::head(const std::string& url, ResponderPtr responder, const F32 timeout) 313void LLHTTPClient::head(
314 const std::string& url,
315 ResponderPtr responder,
316 const LLSD& headers,
317 const F32 timeout)
288{ 318{
289 request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout); 319 request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers);
290} 320}
291 321
292void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout) 322void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout)
@@ -397,39 +427,66 @@ LLSD LLHTTPClient::blockingGet(const std::string& url)
397 return response; 427 return response;
398} 428}
399 429
400void LLHTTPClient::put(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout) 430void LLHTTPClient::put(
431 const std::string& url,
432 const LLSD& body,
433 ResponderPtr responder,
434 const LLSD& headers,
435 const F32 timeout)
401{ 436{
402 request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, timeout); 437 request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, timeout, headers);
403} 438}
404 439
405void LLHTTPClient::post(const std::string& url, const LLSD& body, ResponderPtr responder, const F32 timeout) 440void LLHTTPClient::post(
441 const std::string& url,
442 const LLSD& body,
443 ResponderPtr responder,
444 const LLSD& headers,
445 const F32 timeout)
406{ 446{
407 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout); 447 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout, headers);
408} 448}
409 449
410void LLHTTPClient::postRaw(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout) 450void LLHTTPClient::postRaw(
451 const std::string& url,
452 const U8* data,
453 S32 size,
454 ResponderPtr responder,
455 const LLSD& headers,
456 const F32 timeout)
411{ 457{
412 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout); 458 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout, headers);
413} 459}
414 460
415void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder, const F32 timeout) 461void LLHTTPClient::postFile(
462 const std::string& url,
463 const std::string& filename,
464 ResponderPtr responder,
465 const LLSD& headers,
466 const F32 timeout)
416{ 467{
417 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout); 468 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout, headers);
418} 469}
419 470
420void LLHTTPClient::postFile(const std::string& url, const LLUUID& uuid, 471void LLHTTPClient::postFile(
421 LLAssetType::EType asset_type, ResponderPtr responder, const F32 timeout) 472 const std::string& url,
473 const LLUUID& uuid,
474 LLAssetType::EType asset_type,
475 ResponderPtr responder,
476 const LLSD& headers,
477 const F32 timeout)
422{ 478{
423 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout); 479 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout, headers);
424} 480}
425 481
426// static 482// static
427void LLHTTPClient::del( 483void LLHTTPClient::del(
428 const std::string& url, 484 const std::string& url,
429 ResponderPtr responder, 485 ResponderPtr responder,
486 const LLSD& headers,
430 const F32 timeout) 487 const F32 timeout)
431{ 488{
432 request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout); 489 request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout, headers);
433} 490}
434 491
435// static 492// static
@@ -437,9 +494,10 @@ void LLHTTPClient::move(
437 const std::string& url, 494 const std::string& url,
438 const std::string& destination, 495 const std::string& destination,
439 ResponderPtr responder, 496 ResponderPtr responder,
497 const LLSD& hdrs,
440 const F32 timeout) 498 const F32 timeout)
441{ 499{
442 LLSD headers; 500 LLSD headers = hdrs;
443 headers["Destination"] = destination; 501 headers["Destination"] = destination;
444 request(url, LLURLRequest::HTTP_MOVE, NULL, responder, timeout, headers); 502 request(url, LLURLRequest::HTTP_MOVE, NULL, responder, timeout, headers);
445} 503}