aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lliohttpserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/lliohttpserver.cpp52
1 files changed, 37 insertions, 15 deletions
diff --git a/linden/indra/llmessage/lliohttpserver.cpp b/linden/indra/llmessage/lliohttpserver.cpp
index 2ebf117..d4155f6 100644
--- a/linden/indra/llmessage/lliohttpserver.cpp
+++ b/linden/indra/llmessage/lliohttpserver.cpp
@@ -57,10 +57,13 @@
57static const char HTTP_VERSION_STR[] = "HTTP/1.0"; 57static const char HTTP_VERSION_STR[] = "HTTP/1.0";
58static const std::string CONTEXT_REQUEST("request"); 58static const std::string CONTEXT_REQUEST("request");
59static const std::string CONTEXT_RESPONSE("response"); 59static const std::string CONTEXT_RESPONSE("response");
60static const std::string CONTEXT_VERB("verb");
61static const std::string CONTEXT_HEADERS("headers");
60static const std::string HTTP_VERB_GET("GET"); 62static const std::string HTTP_VERB_GET("GET");
61static const std::string HTTP_VERB_PUT("PUT"); 63static const std::string HTTP_VERB_PUT("PUT");
62static const std::string HTTP_VERB_POST("POST"); 64static const std::string HTTP_VERB_POST("POST");
63static const std::string HTTP_VERB_DELETE("DELETE"); 65static const std::string HTTP_VERB_DELETE("DELETE");
66static const std::string HTTP_VERB_OPTIONS("OPTIONS");
64 67
65static LLIOHTTPServer::timing_callback_t sTimingCallback = NULL; 68static LLIOHTTPServer::timing_callback_t sTimingCallback = NULL;
66static void* sTimingCallbackData = NULL; 69static void* sTimingCallbackData = NULL;
@@ -130,6 +133,7 @@ private:
130 LLSD mGoodResult; 133 LLSD mGoodResult;
131 S32 mStatusCode; 134 S32 mStatusCode;
132 std::string mStatusMessage; 135 std::string mStatusMessage;
136 LLSD mHeaders;
133}; 137};
134 138
135LLIOPipe::EStatus LLHTTPPipe::process_impl( 139LLIOPipe::EStatus LLHTTPPipe::process_impl(
@@ -164,7 +168,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
164 static LLTimer timer; 168 static LLTimer timer;
165 timer.reset(); 169 timer.reset();
166 170
167 std::string verb = context[CONTEXT_REQUEST]["verb"]; 171 std::string verb = context[CONTEXT_REQUEST][CONTEXT_VERB];
168 if(verb == HTTP_VERB_GET) 172 if(verb == HTTP_VERB_GET)
169 { 173 {
170 mNode.get(LLHTTPNode::ResponsePtr(mResponse), context); 174 mNode.get(LLHTTPNode::ResponsePtr(mResponse), context);
@@ -185,6 +189,10 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
185 { 189 {
186 mNode.del(LLHTTPNode::ResponsePtr(mResponse), context); 190 mNode.del(LLHTTPNode::ResponsePtr(mResponse), context);
187 } 191 }
192 else if(verb == HTTP_VERB_OPTIONS)
193 {
194 mNode.options(LLHTTPNode::ResponsePtr(mResponse), context);
195 }
188 else 196 else
189 { 197 {
190 mResponse->methodNotAllowed(); 198 mResponse->methodNotAllowed();
@@ -231,7 +239,9 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
231 239
232 case STATE_GOOD_RESULT: 240 case STATE_GOOD_RESULT:
233 { 241 {
234 context[CONTEXT_RESPONSE]["contentType"] = "application/xml"; 242 LLSD headers = mHeaders;
243 headers["Content-Type"] = "application/xml";
244 context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = headers;
235 LLBufferStream ostr(channels, buffer.get()); 245 LLBufferStream ostr(channels, buffer.get());
236 LLSDSerialize::toXML(mGoodResult, ostr); 246 LLSDSerialize::toXML(mGoodResult, ostr);
237 247
@@ -240,7 +250,9 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
240 250
241 case STATE_STATUS_RESULT: 251 case STATE_STATUS_RESULT:
242 { 252 {
243 context[CONTEXT_RESPONSE]["contentType"] = "text/plain"; 253 LLSD headers = mHeaders;
254 headers["Content-Type"] = "text/plain";
255 context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = headers;
244 context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode; 256 context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode;
245 context[CONTEXT_RESPONSE]["statusMessage"] = mStatusMessage; 257 context[CONTEXT_RESPONSE]["statusMessage"] = mStatusMessage;
246 LLBufferStream ostr(channels, buffer.get()); 258 LLBufferStream ostr(channels, buffer.get());
@@ -287,6 +299,7 @@ void LLHTTPPipe::Response::result(const LLSD& r)
287 mPipe->mStatusMessage = "OK"; 299 mPipe->mStatusMessage = "OK";
288 mPipe->mGoodResult = r; 300 mPipe->mGoodResult = r;
289 mPipe->mState = STATE_GOOD_RESULT; 301 mPipe->mState = STATE_GOOD_RESULT;
302 mPipe->mHeaders = mHeaders;
290 mPipe->unlockChain(); 303 mPipe->unlockChain();
291} 304}
292 305
@@ -302,6 +315,7 @@ void LLHTTPPipe::Response::status(S32 code, const std::string& message)
302 mPipe->mStatusCode = code; 315 mPipe->mStatusCode = code;
303 mPipe->mStatusMessage = message; 316 mPipe->mStatusMessage = message;
304 mPipe->mState = STATE_STATUS_RESULT; 317 mPipe->mState = STATE_STATUS_RESULT;
318 mPipe->mHeaders = mHeaders;
305 mPipe->unlockChain(); 319 mPipe->unlockChain();
306} 320}
307 321
@@ -389,17 +403,24 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
389 } 403 }
390 404
391 ostr << HTTP_VERSION_STR << " " << code << " " << message << "\r\n"; 405 ostr << HTTP_VERSION_STR << " " << code << " " << message << "\r\n";
392
393 std::string type = context[CONTEXT_RESPONSE]["contentType"].asString();
394 if (!type.empty())
395 {
396 ostr << "Content-Type: " << type << "\r\n";
397 }
398 S32 content_length = buffer->countAfter(channels.in(), NULL); 406 S32 content_length = buffer->countAfter(channels.in(), NULL);
399 if(0 < content_length) 407 if(0 < content_length)
400 { 408 {
401 ostr << "Content-Length: " << content_length << "\r\n"; 409 ostr << "Content-Length: " << content_length << "\r\n";
402 } 410 }
411 // *NOTE: This guard can go away once the LLSD static map
412 // iterator is available. Phoenix. 2008-05-09
413 LLSD headers = context[CONTEXT_RESPONSE][CONTEXT_HEADERS];
414 if(headers.isDefined())
415 {
416 LLSD::map_iterator iter = headers.beginMap();
417 LLSD::map_iterator end = headers.endMap();
418 for(; iter != end; ++iter)
419 {
420 ostr << (*iter).first << ": " << (*iter).second.asString()
421 << "\r\n";
422 }
423 }
403 ostr << "\r\n"; 424 ostr << "\r\n";
404 425
405 LLChangeChannel change(channels.in(), channels.out()); 426 LLChangeChannel change(channels.in(), channels.out());
@@ -606,11 +627,12 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
606 read_next_line = true; 627 read_next_line = true;
607 LLMemoryStream header((U8*)buf, len); 628 LLMemoryStream header((U8*)buf, len);
608 header >> mVerb; 629 header >> mVerb;
609 630
610 if((HTTP_VERB_GET == mVerb) 631 if((HTTP_VERB_GET == mVerb)
611 || (HTTP_VERB_POST == mVerb) 632 || (HTTP_VERB_POST == mVerb)
612 || (HTTP_VERB_PUT == mVerb) 633 || (HTTP_VERB_PUT == mVerb)
613 || (HTTP_VERB_DELETE == mVerb)) 634 || (HTTP_VERB_DELETE == mVerb)
635 || (HTTP_VERB_OPTIONS == mVerb))
614 { 636 {
615 header >> mAbsPathAndQuery; 637 header >> mAbsPathAndQuery;
616 header >> mVersion; 638 header >> mVersion;
@@ -685,7 +707,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
685 read_next_line = true; 707 read_next_line = true;
686 std::string name(buf, pos_colon - buf); 708 std::string name(buf, pos_colon - buf);
687 std::string value(pos_colon + 2); 709 std::string value(pos_colon + 2);
688 LLString::toLower(name); 710 LLStringUtil::toLower(name);
689 if("content-length" == name) 711 if("content-length" == name)
690 { 712 {
691 lldebugs << "Content-Length: " << value << llendl; 713 lldebugs << "Content-Length: " << value << llendl;
@@ -693,7 +715,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
693 } 715 }
694 else 716 else
695 { 717 {
696 LLString::trimTail(value); 718 LLStringUtil::trimTail(value);
697 mHeaders[name] = value; 719 mHeaders[name] = value;
698 } 720 }
699 } 721 }
@@ -721,7 +743,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
721 { 743 {
722 // hey, hey, we should have everything now, so we pass it to 744 // hey, hey, we should have everything now, so we pass it to
723 // a content handler. 745 // a content handler.
724 context[CONTEXT_REQUEST]["verb"] = mVerb; 746 context[CONTEXT_REQUEST][CONTEXT_VERB] = mVerb;
725 const LLHTTPNode* node = mRootNode.traverse(mPath, context); 747 const LLHTTPNode* node = mRootNode.traverse(mPath, context);
726 if(node) 748 if(node)
727 { 749 {
@@ -765,7 +787,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
765 = mBuildContext["remote-host"]; 787 = mBuildContext["remote-host"];
766 context[CONTEXT_REQUEST]["remote-port"] 788 context[CONTEXT_REQUEST]["remote-port"]
767 = mBuildContext["remote-port"]; 789 = mBuildContext["remote-port"];
768 context[CONTEXT_REQUEST]["headers"] = mHeaders; 790 context[CONTEXT_REQUEST][CONTEXT_HEADERS] = mHeaders;
769 791
770 const LLChainIOFactory* protocolHandler 792 const LLChainIOFactory* protocolHandler
771 = node->getProtocolHandler(); 793 = node->getProtocolHandler();