summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/httprequest.cpp
diff options
context:
space:
mode:
authorMonty Brandenberg <monty@lindenlab.com>2012-06-12 17:42:33 -0400
committerMonty Brandenberg <monty@lindenlab.com>2012-06-12 17:42:33 -0400
commit7adeb3923728ca84a309a6af141c148ce38066fc (patch)
tree1d2395b61eaa90b670fdd356bb8010b75b49f99a /indra/llcorehttp/httprequest.cpp
parent24e16e1632974057013b86300bb60954ea6f5684 (diff)
HTTP Proxy, PUT & POST, unit tests and refactoring.
Implemented/modified PUT & POST to not used chunked encoding for the request. Made the unit test much happier and probably a better thing for the pipeline. Have a cheesy static & dynamic proxy capability using both local options and a way to wire into LLProxy in llmessages. Not a clean thing but it will get the proxy path working with both socks5 & http proxies. Refactoring to get rid of unneeded library handler and unified an HttpStatus return for all requests. Big batch of code removed as a result of that and more is possible as well as some syscall avoidance with a bit more work. Boosted the unit tests for simple PUT & POST test which revealed the test harness does *not* like chunked encoding so we'll avoid it for now (and don't really need it in any of our schemes).
Diffstat (limited to 'indra/llcorehttp/httprequest.cpp')
-rw-r--r--indra/llcorehttp/httprequest.cpp151
1 files changed, 80 insertions, 71 deletions
diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp
index 2f36168f8b..089eee76f3 100644
--- a/indra/llcorehttp/httprequest.cpp
+++ b/indra/llcorehttp/httprequest.cpp
@@ -34,6 +34,7 @@
#include "_httpoprequest.h"
#include "_httpopsetpriority.h"
#include "_httpopcancel.h"
+#include "_httpopsetget.h"
#include "lltimer.h"
@@ -49,39 +50,6 @@ namespace LLCore
{
// ====================================
-// InternalHandler Implementation
-// ====================================
-
-
-class HttpRequest::InternalHandler : public HttpHandler
-{
-public:
- InternalHandler(HttpRequest & request)
- : mRequest(request)
- {}
-
-protected:
- InternalHandler(const InternalHandler &); // Not defined
- void operator=(const InternalHandler &); // Not defined
-
-public:
- void onCompleted(HttpHandle handle, HttpResponse * response)
- {
- HttpOperation * op(static_cast<HttpOperation *>(handle));
- HttpHandler * user_handler(op->getUserHandler());
- if (user_handler)
- {
- user_handler->onCompleted(handle, response);
- }
- }
-
-protected:
- HttpRequest & mRequest;
-
-}; // end class HttpRequest::InternalHandler
-
-
-// ====================================
// HttpRequest Implementation
// ====================================
@@ -92,15 +60,12 @@ HttpRequest::policy_t HttpRequest::sNextPolicyID(1);
HttpRequest::HttpRequest()
: //HttpHandler(),
mReplyQueue(NULL),
- mRequestQueue(NULL),
- mSelfHandler(NULL)
+ mRequestQueue(NULL)
{
mRequestQueue = HttpRequestQueue::instanceOf();
mRequestQueue->addRef();
mReplyQueue = new HttpReplyQueue();
-
- mSelfHandler = new InternalHandler(*this);
}
@@ -117,9 +82,6 @@ HttpRequest::~HttpRequest()
mReplyQueue->release();
mReplyQueue = NULL;
}
-
- delete mSelfHandler;
- mSelfHandler = NULL;
}
@@ -132,7 +94,7 @@ HttpStatus HttpRequest::setPolicyGlobalOption(EGlobalPolicy opt, long value)
{
// *FIXME: Fail if thread is running.
- return HttpService::instanceOf()->getPolicy().getGlobalOptions().set(opt, value);
+ return HttpService::instanceOf()->getGlobalOptions().set(opt, value);
}
@@ -140,7 +102,7 @@ HttpStatus HttpRequest::setPolicyGlobalOption(EGlobalPolicy opt, const std::stri
{
// *FIXME: Fail if thread is running.
- return HttpService::instanceOf()->getPolicy().getGlobalOptions().set(opt, value);
+ return HttpService::instanceOf()->getGlobalOptions().set(opt, value);
}
@@ -192,7 +154,7 @@ HttpHandle HttpRequest::requestGetByteRange(policy_t policy_id,
mLastReqStatus = status;
return handle;
}
- op->setHandlers(mReplyQueue, mSelfHandler, user_handler);
+ op->setReplyPath(mReplyQueue, user_handler);
mRequestQueue->addOp(op); // transfers refcount
mLastReqStatus = status;
@@ -220,7 +182,7 @@ HttpHandle HttpRequest::requestPost(policy_t policy_id,
mLastReqStatus = status;
return handle;
}
- op->setHandlers(mReplyQueue, mSelfHandler, user_handler);
+ op->setReplyPath(mReplyQueue, user_handler);
mRequestQueue->addOp(op); // transfers refcount
mLastReqStatus = status;
@@ -230,19 +192,31 @@ HttpHandle HttpRequest::requestPost(policy_t policy_id,
}
-HttpHandle HttpRequest::requestCancel(HttpHandle handle, HttpHandler * user_handler)
+HttpHandle HttpRequest::requestPut(policy_t policy_id,
+ priority_t priority,
+ const std::string & url,
+ BufferArray * body,
+ HttpOptions * options,
+ HttpHeaders * headers,
+ HttpHandler * user_handler)
{
HttpStatus status;
- HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID);
-
- HttpOpCancel * op = new HttpOpCancel(handle);
- op->setHandlers(mReplyQueue, mSelfHandler, user_handler);
- mRequestQueue->addOp(op); // transfer refcount as well
+ HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID);
+ HttpOpRequest * op = new HttpOpRequest();
+ if (! (status = op->setupPut(policy_id, priority, url, body, options, headers)))
+ {
+ op->release();
+ mLastReqStatus = status;
+ return handle;
+ }
+ op->setReplyPath(mReplyQueue, user_handler);
+ mRequestQueue->addOp(op); // transfers refcount
+
mLastReqStatus = status;
- ret_handle = static_cast<HttpHandle>(op);
+ handle = static_cast<HttpHandle>(op);
- return ret_handle;
+ return handle;
}
@@ -252,7 +226,7 @@ HttpHandle HttpRequest::requestNoOp(HttpHandler * user_handler)
HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID);
HttpOpNull * op = new HttpOpNull();
- op->setHandlers(mReplyQueue, mSelfHandler, user_handler);
+ op->setReplyPath(mReplyQueue, user_handler);
mRequestQueue->addOp(op); // transfer refcount as well
mLastReqStatus = status;
@@ -262,23 +236,6 @@ HttpHandle HttpRequest::requestNoOp(HttpHandler * user_handler)
}
-HttpHandle HttpRequest::requestSetPriority(HttpHandle request, priority_t priority,
- HttpHandler * handler)
-{
- HttpStatus status;
- HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID);
-
- HttpOpSetPriority * op = new HttpOpSetPriority(request, priority);
- op->setHandlers(mReplyQueue, mSelfHandler, handler);
- mRequestQueue->addOp(op); // transfer refcount as well
-
- mLastReqStatus = status;
- ret_handle = static_cast<HttpHandle>(op);
-
- return ret_handle;
-}
-
-
HttpStatus HttpRequest::update(long millis)
{
const HttpTime limit(totalTime() + (1000 * HttpTime(millis)));
@@ -302,6 +259,38 @@ HttpStatus HttpRequest::update(long millis)
// Request Management Methods
// ====================================
+HttpHandle HttpRequest::requestCancel(HttpHandle handle, HttpHandler * user_handler)
+{
+ HttpStatus status;
+ HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID);
+
+ HttpOpCancel * op = new HttpOpCancel(handle);
+ op->setReplyPath(mReplyQueue, user_handler);
+ mRequestQueue->addOp(op); // transfer refcount as well
+
+ mLastReqStatus = status;
+ ret_handle = static_cast<HttpHandle>(op);
+
+ return ret_handle;
+}
+
+
+HttpHandle HttpRequest::requestSetPriority(HttpHandle request, priority_t priority,
+ HttpHandler * handler)
+{
+ HttpStatus status;
+ HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID);
+
+ HttpOpSetPriority * op = new HttpOpSetPriority(request, priority);
+ op->setReplyPath(mReplyQueue, handler);
+ mRequestQueue->addOp(op); // transfer refcount as well
+
+ mLastReqStatus = status;
+ ret_handle = static_cast<HttpHandle>(op);
+
+ return ret_handle;
+}
+
// ====================================
// Utility Methods
@@ -350,7 +339,27 @@ HttpHandle HttpRequest::requestStopThread(HttpHandler * user_handler)
HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID);
HttpOpStop * op = new HttpOpStop();
- op->setHandlers(mReplyQueue, mSelfHandler, user_handler);
+ op->setReplyPath(mReplyQueue, user_handler);
+ mRequestQueue->addOp(op); // transfer refcount as well
+
+ mLastReqStatus = status;
+ handle = static_cast<HttpHandle>(op);
+
+ return handle;
+}
+
+// ====================================
+// Dynamic Policy Methods
+// ====================================
+
+HttpHandle HttpRequest::requestSetHttpProxy(const std::string & proxy, HttpHandler * handler)
+{
+ HttpStatus status;
+ HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID);
+
+ HttpOpSetGet * op = new HttpOpSetGet();
+ op->setupSet(GP_HTTP_PROXY, proxy);
+ op->setReplyPath(mReplyQueue, handler);
mRequestQueue->addOp(op); // transfer refcount as well
mLastReqStatus = status;