aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lliohttpserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/lliohttpserver.cpp')
-rw-r--r--linden/indra/llmessage/lliohttpserver.cpp75
1 files changed, 61 insertions, 14 deletions
diff --git a/linden/indra/llmessage/lliohttpserver.cpp b/linden/indra/llmessage/lliohttpserver.cpp
index 167f212..83dfa94 100644
--- a/linden/indra/llmessage/lliohttpserver.cpp
+++ b/linden/indra/llmessage/lliohttpserver.cpp
@@ -19,7 +19,8 @@
19 * There are special exceptions to the terms and conditions of the GPL as 19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception 20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or 21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception 22 * online at
23 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 * 24 *
24 * By copying, modifying or distributing this software, you acknowledge 25 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above, 26 * that you have read and understood your obligations described above,
@@ -56,15 +57,15 @@
56#include <boost/tokenizer.hpp> 57#include <boost/tokenizer.hpp>
57 58
58static const char HTTP_VERSION_STR[] = "HTTP/1.0"; 59static const char HTTP_VERSION_STR[] = "HTTP/1.0";
59static const std::string CONTEXT_REQUEST("request"); 60const std::string CONTEXT_REQUEST("request");
60static const std::string CONTEXT_RESPONSE("response"); 61const std::string CONTEXT_RESPONSE("response");
61static const std::string CONTEXT_VERB("verb"); 62const std::string CONTEXT_VERB("verb");
62static const std::string CONTEXT_HEADERS("headers"); 63const std::string CONTEXT_HEADERS("headers");
63static const std::string HTTP_VERB_GET("GET"); 64const std::string HTTP_VERB_GET("GET");
64static const std::string HTTP_VERB_PUT("PUT"); 65const std::string HTTP_VERB_PUT("PUT");
65static const std::string HTTP_VERB_POST("POST"); 66const std::string HTTP_VERB_POST("POST");
66static const std::string HTTP_VERB_DELETE("DELETE"); 67const std::string HTTP_VERB_DELETE("DELETE");
67static const std::string HTTP_VERB_OPTIONS("OPTIONS"); 68const std::string HTTP_VERB_OPTIONS("OPTIONS");
68 69
69static LLIOHTTPServer::timing_callback_t sTimingCallback = NULL; 70static LLIOHTTPServer::timing_callback_t sTimingCallback = NULL;
70static void* sTimingCallbackData = NULL; 71static void* sTimingCallbackData = NULL;
@@ -103,6 +104,7 @@ private:
103 104
104 // from LLHTTPNode::Response 105 // from LLHTTPNode::Response
105 virtual void result(const LLSD&); 106 virtual void result(const LLSD&);
107 virtual void extendedResult(S32 code, const std::string& body, const LLSD& headers);
106 virtual void status(S32 code, const std::string& message); 108 virtual void status(S32 code, const std::string& message);
107 109
108 void nullPipe(); 110 void nullPipe();
@@ -121,7 +123,8 @@ private:
121 STATE_DELAYED, 123 STATE_DELAYED,
122 STATE_LOCKED, 124 STATE_LOCKED,
123 STATE_GOOD_RESULT, 125 STATE_GOOD_RESULT,
124 STATE_STATUS_RESULT 126 STATE_STATUS_RESULT,
127 STATE_EXTENDED_RESULT
125 }; 128 };
126 State mState; 129 State mState;
127 130
@@ -179,14 +182,32 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
179 { 182 {
180 LLPerfBlock putblock("http_put"); 183 LLPerfBlock putblock("http_put");
181 LLSD input; 184 LLSD input;
182 LLSDSerialize::fromXML(input, istr); 185 if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_LLSD)
186 {
187 LLSDSerialize::fromXML(input, istr);
188 }
189 else if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_TEXT)
190 {
191 std::stringstream strstrm;
192 strstrm << istr.rdbuf();
193 input = strstrm.str();
194 }
183 mNode.put(LLHTTPNode::ResponsePtr(mResponse), context, input); 195 mNode.put(LLHTTPNode::ResponsePtr(mResponse), context, input);
184 } 196 }
185 else if(verb == HTTP_VERB_POST) 197 else if(verb == HTTP_VERB_POST)
186 { 198 {
187 LLPerfBlock postblock("http_post"); 199 LLPerfBlock postblock("http_post");
188 LLSD input; 200 LLSD input;
189 LLSDSerialize::fromXML(input, istr); 201 if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_LLSD)
202 {
203 LLSDSerialize::fromXML(input, istr);
204 }
205 else if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_TEXT)
206 {
207 std::stringstream strstrm;
208 strstrm << istr.rdbuf();
209 input = strstrm.str();
210 }
190 mNode.post(LLHTTPNode::ResponsePtr(mResponse), context, input); 211 mNode.post(LLHTTPNode::ResponsePtr(mResponse), context, input);
191 } 212 }
192 else if(verb == HTTP_VERB_DELETE) 213 else if(verb == HTTP_VERB_DELETE)
@@ -261,7 +282,16 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
261 context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode; 282 context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode;
262 context[CONTEXT_RESPONSE]["statusMessage"] = mStatusMessage; 283 context[CONTEXT_RESPONSE]["statusMessage"] = mStatusMessage;
263 LLBufferStream ostr(channels, buffer.get()); 284 LLBufferStream ostr(channels, buffer.get());
264 ostr << mStatusMessage << std::ends; 285 ostr << mStatusMessage;
286
287 return STATUS_DONE;
288 }
289 case STATE_EXTENDED_RESULT:
290 {
291 context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = mHeaders;
292 context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode;
293 LLBufferStream ostr(channels, buffer.get());
294 ostr << mStatusMessage;
265 295
266 return STATUS_DONE; 296 return STATUS_DONE;
267 } 297 }
@@ -308,6 +338,21 @@ void LLHTTPPipe::Response::result(const LLSD& r)
308 mPipe->unlockChain(); 338 mPipe->unlockChain();
309} 339}
310 340
341void LLHTTPPipe::Response::extendedResult(S32 code, const std::string& body, const LLSD& headers)
342{
343 if(! mPipe)
344 {
345 llwarns << "LLHTTPPipe::Response::status: NULL pipe" << llendl;
346 return;
347 }
348
349 mPipe->mStatusCode = code;
350 mPipe->mStatusMessage = body;
351 mPipe->mHeaders = headers;
352 mPipe->mState = STATE_EXTENDED_RESULT;
353 mPipe->unlockChain();
354}
355
311// virtual 356// virtual
312void LLHTTPPipe::Response::status(S32 code, const std::string& message) 357void LLHTTPPipe::Response::status(S32 code, const std::string& message)
313{ 358{
@@ -408,6 +453,7 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
408 } 453 }
409 454
410 ostr << HTTP_VERSION_STR << " " << code << " " << message << "\r\n"; 455 ostr << HTTP_VERSION_STR << " " << code << " " << message << "\r\n";
456
411 S32 content_length = buffer->countAfter(channels.in(), NULL); 457 S32 content_length = buffer->countAfter(channels.in(), NULL);
412 if(0 < content_length) 458 if(0 < content_length)
413 { 459 {
@@ -798,6 +844,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
798 = node->getProtocolHandler(); 844 = node->getProtocolHandler();
799 if (protocolHandler) 845 if (protocolHandler)
800 { 846 {
847 lldebugs << "HTTP context: " << context << llendl;
801 protocolHandler->build(chain, context); 848 protocolHandler->build(chain, context);
802 } 849 }
803 else 850 else