diff options
Diffstat (limited to 'indra/llcorehttp')
-rwxr-xr-x | indra/llcorehttp/_httplibcurl.cpp | 2 | ||||
-rwxr-xr-x | indra/llcorehttp/_httpoprequest.cpp | 67 | ||||
-rwxr-xr-x | indra/llcorehttp/_httpoprequest.h | 44 | ||||
-rwxr-xr-x | indra/llcorehttp/examples/http_texture_load.cpp | 18 | ||||
-rwxr-xr-x | indra/llcorehttp/httpheaders.cpp | 1 | ||||
-rwxr-xr-x | indra/llcorehttp/httpheaders.h | 7 | ||||
-rwxr-xr-x | indra/llcorehttp/httpoptions.cpp | 2 | ||||
-rwxr-xr-x | indra/llcorehttp/httpoptions.h | 7 | ||||
-rwxr-xr-x | indra/llcorehttp/httprequest.cpp | 28 | ||||
-rwxr-xr-x | indra/llcorehttp/httprequest.h | 32 | ||||
-rwxr-xr-x | indra/llcorehttp/httpresponse.cpp | 21 | ||||
-rwxr-xr-x | indra/llcorehttp/httpresponse.h | 12 | ||||
-rwxr-xr-x | indra/llcorehttp/tests/test_httpheaders.hpp | 27 | ||||
-rwxr-xr-x | indra/llcorehttp/tests/test_httprequest.hpp | 328 |
14 files changed, 216 insertions, 380 deletions
diff --git a/indra/llcorehttp/_httplibcurl.cpp b/indra/llcorehttp/_httplibcurl.cpp index 81b44ab90b..17e997688f 100755 --- a/indra/llcorehttp/_httplibcurl.cpp +++ b/indra/llcorehttp/_httplibcurl.cpp @@ -554,7 +554,7 @@ void HttpLibcurl::HandleCache::freeHandle(CURL * handle) // --------------------------------------- -struct curl_slist * append_headers_to_slist(const HttpHeaders * headers, struct curl_slist * slist) +struct curl_slist * append_headers_to_slist(const HttpHeaders::ptr_t &headers, struct curl_slist * slist) { const HttpHeaders::const_iterator end(headers->end()); for (HttpHeaders::const_iterator it(headers->begin()); end != it; ++it) diff --git a/indra/llcorehttp/_httpoprequest.cpp b/indra/llcorehttp/_httpoprequest.cpp index 799587ff22..e588ed8a9b 100755 --- a/indra/llcorehttp/_httpoprequest.cpp +++ b/indra/llcorehttp/_httpoprequest.cpp @@ -122,8 +122,8 @@ HttpOpRequest::HttpOpRequest() mReqBody(NULL), mReqOffset(0), mReqLength(0), - mReqHeaders(NULL), - mReqOptions(NULL), + mReqHeaders(), + mReqOptions(), mCurlActive(false), mCurlHandle(NULL), mCurlService(NULL), @@ -135,7 +135,7 @@ HttpOpRequest::HttpOpRequest() mReplyOffset(0), mReplyLength(0), mReplyFullLength(0), - mReplyHeaders(NULL), + mReplyHeaders(), mPolicyRetries(0), mPolicy503Retries(0), mPolicyRetryAt(HttpTime(0)), @@ -156,18 +156,6 @@ HttpOpRequest::~HttpOpRequest() mReqBody = NULL; } - if (mReqOptions) - { - mReqOptions->release(); - mReqOptions = NULL; - } - - if (mReqHeaders) - { - mReqHeaders->release(); - mReqHeaders = NULL; - } - if (mCurlHandle) { // Uncertain of thread context so free using @@ -194,11 +182,6 @@ HttpOpRequest::~HttpOpRequest() mReplyBody = NULL; } - if (mReplyHeaders) - { - mReplyHeaders->release(); - mReplyHeaders = NULL; - } } @@ -298,8 +281,8 @@ HttpStatus HttpOpRequest::cancel() HttpStatus HttpOpRequest::setupGet(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, NULL, options, headers); mReqMethod = HOR_GET; @@ -313,8 +296,8 @@ HttpStatus HttpOpRequest::setupGetByteRange(HttpRequest::policy_t policy_id, const std::string & url, size_t offset, size_t len, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, NULL, options, headers); mReqMethod = HOR_GET; @@ -333,8 +316,8 @@ HttpStatus HttpOpRequest::setupPost(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, body, options, headers); mReqMethod = HOR_POST; @@ -347,8 +330,8 @@ HttpStatus HttpOpRequest::setupPut(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, body, options, headers); mReqMethod = HOR_PUT; @@ -360,8 +343,8 @@ HttpStatus HttpOpRequest::setupPut(HttpRequest::policy_t policy_id, HttpStatus HttpOpRequest::setupDelete(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, NULL, options, headers); mReqMethod = HOR_DELETE; @@ -374,8 +357,8 @@ HttpStatus HttpOpRequest::setupPatch(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { setupCommon(policy_id, priority, url, body, options, headers); mReqMethod = HOR_PATCH; @@ -387,8 +370,8 @@ HttpStatus HttpOpRequest::setupPatch(HttpRequest::policy_t policy_id, HttpStatus HttpOpRequest::setupCopy(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t &headers) { setupCommon(policy_id, priority, url, NULL, options, headers); mReqMethod = HOR_COPY; @@ -401,8 +384,8 @@ void HttpOpRequest::setupCommon(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers) + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers) { mProcFlags = 0U; mReqPolicy = policy_id; @@ -415,12 +398,10 @@ void HttpOpRequest::setupCommon(HttpRequest::policy_t policy_id, } if (headers && ! mReqHeaders) { - headers->addRef(); mReqHeaders = headers; } - if (options && ! mReqOptions) + if (options && !mReqOptions) { - options->addRef(); mReqOptions = options; if (options->getWantHeaders()) { @@ -467,11 +448,7 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) mReplyOffset = 0; mReplyLength = 0; mReplyFullLength = 0; - if (mReplyHeaders) - { - mReplyHeaders->release(); - mReplyHeaders = NULL; - } + mReplyHeaders.reset(); mReplyConType.clear(); // *FIXME: better error handling later @@ -946,7 +923,7 @@ size_t HttpOpRequest::headerCallback(void * data, size_t size, size_t nmemb, voi // Save headers in response if (! op->mReplyHeaders) { - op->mReplyHeaders = new HttpHeaders; + op->mReplyHeaders = HttpHeaders::ptr_t(new HttpHeaders); } op->mReplyHeaders->append(name, value ? value : ""); } diff --git a/indra/llcorehttp/_httpoprequest.h b/indra/llcorehttp/_httpoprequest.h index b1bb101bea..a9083be02b 100755 --- a/indra/llcorehttp/_httpoprequest.h +++ b/indra/llcorehttp/_httpoprequest.h @@ -41,14 +41,14 @@ #include "_httpoperation.h" #include "_refcounted.h" +#include "httpheaders.h" +#include "httpoptions.h" namespace LLCore { class BufferArray; -class HttpHeaders; -class HttpOptions; /// HttpOpRequest requests a supported HTTP method invocation with @@ -104,49 +104,49 @@ public: HttpStatus setupGet(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupGetByteRange(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, size_t offset, size_t len, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupPost(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupPut(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupDelete(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupPatch(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); HttpStatus setupCopy(HttpRequest::policy_t policy_id, HttpRequest::priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); // Internal method used to setup the libcurl options for a request. // Does all the libcurl handle setup in one place. @@ -166,8 +166,8 @@ protected: HttpRequest::priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers); + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers); // libcurl operational callbacks // @@ -197,8 +197,8 @@ public: BufferArray * mReqBody; off_t mReqOffset; size_t mReqLength; - HttpHeaders * mReqHeaders; - HttpOptions * mReqOptions; + HttpHeaders::ptr_t mReqHeaders; + HttpOptions::ptr_t mReqOptions; // Transport data bool mCurlActive; @@ -215,7 +215,7 @@ public: off_t mReplyOffset; size_t mReplyLength; size_t mReplyFullLength; - HttpHeaders * mReplyHeaders; + HttpHeaders::ptr_t mReplyHeaders; std::string mReplyConType; int mReplyRetryAfter; @@ -246,7 +246,7 @@ public: // Internal function to append the contents of an HttpHeaders // instance to a curl_slist object. -curl_slist * append_headers_to_slist(const HttpHeaders *, curl_slist * slist); +curl_slist * append_headers_to_slist(const HttpHeaders::ptr_t &, curl_slist * slist); } // end namespace LLCore diff --git a/indra/llcorehttp/examples/http_texture_load.cpp b/indra/llcorehttp/examples/http_texture_load.cpp index 9d9631b980..737282c7df 100755 --- a/indra/llcorehttp/examples/http_texture_load.cpp +++ b/indra/llcorehttp/examples/http_texture_load.cpp @@ -83,7 +83,7 @@ public: WorkingSet(); ~WorkingSet(); - bool reload(LLCore::HttpRequest *, LLCore::HttpOptions *); + bool reload(LLCore::HttpRequest *, LLCore::HttpOptions::ptr_t &); virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response); @@ -121,7 +121,7 @@ public: int mRetriesHttp503; int mSuccesses; long mByteCount; - LLCore::HttpHeaders * mHeaders; + LLCore::HttpHeaders::ptr_t mHeaders; }; @@ -304,7 +304,7 @@ int main(int argc, char** argv) LLCore::HttpRequest * hr = new LLCore::HttpRequest(); // Get request options - LLCore::HttpOptions * opt = new LLCore::HttpOptions(); + LLCore::HttpOptions::ptr_t opt = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()); opt->setRetries(12); opt->setUseRetryAfter(true); @@ -363,8 +363,7 @@ int main(int argc, char** argv) // Clean up hr->requestStopThread(NULL); ms_sleep(1000); - opt->release(); - opt = NULL; + opt.reset(); delete hr; LLCore::HttpRequest::destroyService(); term_curl(); @@ -427,22 +426,17 @@ WorkingSet::WorkingSet() { mAssets.reserve(30000); - mHeaders = new LLCore::HttpHeaders; + mHeaders = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders); mHeaders->append("Accept", "image/x-j2c"); } WorkingSet::~WorkingSet() { - if (mHeaders) - { - mHeaders->release(); - mHeaders = NULL; - } } -bool WorkingSet::reload(LLCore::HttpRequest * hr, LLCore::HttpOptions * opt) +bool WorkingSet::reload(LLCore::HttpRequest * hr, LLCore::HttpOptions::ptr_t & opt) { if (mRequestLowWater <= mHandles.size()) { diff --git a/indra/llcorehttp/httpheaders.cpp b/indra/llcorehttp/httpheaders.cpp index e03b1b080d..f586191a7c 100755 --- a/indra/llcorehttp/httpheaders.cpp +++ b/indra/llcorehttp/httpheaders.cpp @@ -34,7 +34,6 @@ namespace LLCore HttpHeaders::HttpHeaders() - : RefCounted(true) {} diff --git a/indra/llcorehttp/httpheaders.h b/indra/llcorehttp/httpheaders.h index 8f14568fa3..b9168cb6ec 100755 --- a/indra/llcorehttp/httpheaders.h +++ b/indra/llcorehttp/httpheaders.h @@ -74,7 +74,7 @@ namespace LLCore /// constructor is given a refcount. /// -class HttpHeaders : public LLCoreInt::RefCounted +class HttpHeaders: private boost::noncopyable { public: typedef std::pair<std::string, std::string> header_t; @@ -85,16 +85,17 @@ public: typedef container_t::const_reverse_iterator const_reverse_iterator; typedef container_t::value_type value_type; typedef container_t::size_type size_type; + typedef boost::shared_ptr<HttpHeaders> ptr_t; public: /// @post In addition to the instance, caller has a refcount /// to the instance. A call to @see release() will destroy /// the instance. HttpHeaders(); + virtual ~HttpHeaders(); // Use release() - typedef LLCoreInt::IntrusivePtr<HttpHeaders> ptr_t; + //typedef LLCoreInt::IntrusivePtr<HttpHeaders> ptr_t; protected: - virtual ~HttpHeaders(); // Use release() HttpHeaders(const HttpHeaders &); // Not defined void operator=(const HttpHeaders &); // Not defined diff --git a/indra/llcorehttp/httpoptions.cpp b/indra/llcorehttp/httpoptions.cpp index 3459a37aff..aab447f2dd 100755 --- a/indra/llcorehttp/httpoptions.cpp +++ b/indra/llcorehttp/httpoptions.cpp @@ -33,7 +33,7 @@ namespace LLCore { -HttpOptions::HttpOptions() : RefCounted(true), +HttpOptions::HttpOptions() : mWantHeaders(false), mTracing(HTTP_TRACE_OFF), mTimeout(HTTP_REQUEST_TIMEOUT_DEFAULT), diff --git a/indra/llcorehttp/httpoptions.h b/indra/llcorehttp/httpoptions.h index 2fe05a65ff..510eaa45bb 100755 --- a/indra/llcorehttp/httpoptions.h +++ b/indra/llcorehttp/httpoptions.h @@ -55,15 +55,16 @@ namespace LLCore /// Allocation: Refcounted, heap only. Caller of the constructor /// is given a refcount. /// -class HttpOptions : public LLCoreInt::RefCounted +class HttpOptions : private boost::noncopyable { public: HttpOptions(); - typedef LLCoreInt::IntrusivePtr<HttpOptions> ptr_t; + typedef boost::shared_ptr<HttpOptions> ptr_t; + + virtual ~HttpOptions(); // Use release() protected: - virtual ~HttpOptions(); // Use release() HttpOptions(const HttpOptions &); // Not defined void operator=(const HttpOptions &); // Not defined diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp index d4c60a6f14..f0dfde6153 100755 --- a/indra/llcorehttp/httprequest.cpp +++ b/indra/llcorehttp/httprequest.cpp @@ -197,8 +197,8 @@ HttpStatus HttpRequest::getStatus() const HttpHandle HttpRequest::requestGet(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -231,8 +231,8 @@ HttpHandle HttpRequest::requestGetByteRange(policy_t policy_id, const std::string & url, size_t offset, size_t len, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -264,8 +264,8 @@ HttpHandle HttpRequest::requestPost(policy_t policy_id, priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -297,8 +297,8 @@ HttpHandle HttpRequest::requestPut(policy_t policy_id, priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -328,8 +328,8 @@ HttpHandle HttpRequest::requestPut(policy_t policy_id, HttpHandle HttpRequest::requestDelete(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -360,8 +360,8 @@ HttpHandle HttpRequest::requestPatch(policy_t policy_id, priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; @@ -391,8 +391,8 @@ HttpHandle HttpRequest::requestPatch(policy_t policy_id, HttpHandle HttpRequest::requestCopy(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler) { HttpStatus status; diff --git a/indra/llcorehttp/httprequest.h b/indra/llcorehttp/httprequest.h index e87a8b691a..20a223c482 100755 --- a/indra/llcorehttp/httprequest.h +++ b/indra/llcorehttp/httprequest.h @@ -31,6 +31,8 @@ #include "httpcommon.h" #include "httphandler.h" +#include "httpheaders.h" +#include "httpoptions.h" namespace LLCore { @@ -38,8 +40,6 @@ namespace LLCore class HttpRequestQueue; class HttpReplyQueue; class HttpService; -class HttpOptions; -class HttpHeaders; class HttpOperation; class BufferArray; @@ -348,8 +348,8 @@ public: HttpHandle requestGet(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * handler); @@ -391,8 +391,8 @@ public: const std::string & url, size_t offset, size_t len, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * handler); @@ -432,8 +432,8 @@ public: priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * handler); @@ -473,8 +473,8 @@ public: priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * handler); @@ -493,8 +493,8 @@ public: HttpHandle requestDelete(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler); /// Queue a full HTTP PUT. Query arguments and body may @@ -516,8 +516,8 @@ public: priority_t priority, const std::string & url, BufferArray * body, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler); /// Queue a full HTTP PUT. Query arguments and body may @@ -535,8 +535,8 @@ public: HttpHandle requestCopy(policy_t policy_id, priority_t priority, const std::string & url, - HttpOptions * options, - HttpHeaders * headers, + const HttpOptions::ptr_t & options, + const HttpHeaders::ptr_t & headers, HttpHandler * user_handler); /// Queue a NoOp request. diff --git a/indra/llcorehttp/httpresponse.cpp b/indra/llcorehttp/httpresponse.cpp index 7d88f02527..f5ad2ebd47 100755 --- a/indra/llcorehttp/httpresponse.cpp +++ b/indra/llcorehttp/httpresponse.cpp @@ -39,7 +39,7 @@ HttpResponse::HttpResponse() mReplyLength(0U), mReplyFullLength(0U), mBufferArray(NULL), - mHeaders(NULL), + mHeaders(), mRetries(0U), m503Retries(0U), mRequestUrl() @@ -49,7 +49,7 @@ HttpResponse::HttpResponse() HttpResponse::~HttpResponse() { setBody(NULL); - setHeaders(NULL); + //setHeaders(); } @@ -72,22 +72,9 @@ void HttpResponse::setBody(BufferArray * ba) } -void HttpResponse::setHeaders(HttpHeaders * headers) +void HttpResponse::setHeaders(HttpHeaders::ptr_t &headers) { - if (mHeaders == headers) - return; - - if (mHeaders) - { - mHeaders->release(); - } - - if (headers) - { - headers->addRef(); - } - - mHeaders = headers; + mHeaders = headers; } size_t HttpResponse::getBodySize() const diff --git a/indra/llcorehttp/httpresponse.h b/indra/llcorehttp/httpresponse.h index 6c3b4da5e6..0bfa4585c7 100755 --- a/indra/llcorehttp/httpresponse.h +++ b/indra/llcorehttp/httpresponse.h @@ -31,7 +31,7 @@ #include <string> #include "httpcommon.h" - +#include "httpheaders.h" #include "_refcounted.h" @@ -120,13 +120,13 @@ public: /// /// Caller can hold onto the headers by incrementing the reference /// count of the returned object. - HttpHeaders * getHeaders() const - { + HttpHeaders::ptr_t getHeaders() const + { return mHeaders; - } + } /// Behaves like @see setResponse() but for header data. - void setHeaders(HttpHeaders * headers); + void setHeaders(HttpHeaders::ptr_t &headers); /// If a 'Range:' header was used, these methods are involved /// in setting and returning data about the actual response. @@ -212,7 +212,7 @@ protected: unsigned int mReplyLength; unsigned int mReplyFullLength; BufferArray * mBufferArray; - HttpHeaders * mHeaders; + HttpHeaders::ptr_t mHeaders; std::string mContentType; unsigned int mRetries; unsigned int m503Retries; diff --git a/indra/llcorehttp/tests/test_httpheaders.hpp b/indra/llcorehttp/tests/test_httpheaders.hpp index 668c36dc66..c05f1d9429 100755 --- a/indra/llcorehttp/tests/test_httpheaders.hpp +++ b/indra/llcorehttp/tests/test_httpheaders.hpp @@ -59,13 +59,12 @@ void HttpHeadersTestObjectType::test<1>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); - ensure("One ref on construction of HttpHeaders", headers->getRefCount() == 1); + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); ensure("Memory being used", mMemTotal < GetMemTotal()); ensure("Nothing in headers", 0 == headers->size()); // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -80,7 +79,7 @@ void HttpHeadersTestObjectType::test<2>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); { // Append a few strings @@ -101,7 +100,7 @@ void HttpHeadersTestObjectType::test<2>() } // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -116,7 +115,7 @@ void HttpHeadersTestObjectType::test<3>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); { // Append a few strings @@ -151,7 +150,7 @@ void HttpHeadersTestObjectType::test<3>() } // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -166,8 +165,8 @@ void HttpHeadersTestObjectType::test<4>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); - + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); + { static char line1[] = " AcCePT : image/yourfacehere"; static char line1v[] = "image/yourfacehere"; @@ -251,7 +250,7 @@ void HttpHeadersTestObjectType::test<4>() } // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -267,7 +266,7 @@ void HttpHeadersTestObjectType::test<5>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); HttpHeaders::iterator end(headers->end()), begin(headers->begin()); ensure("Empty container has equal begin/end const iterators", end == begin); @@ -337,7 +336,7 @@ void HttpHeadersTestObjectType::test<5>() } // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -353,7 +352,7 @@ void HttpHeadersTestObjectType::test<6>() mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpHeaders * headers = new HttpHeaders(); + HttpHeaders::ptr_t headers = HttpHeaders::ptr_t(new HttpHeaders()); HttpHeaders::reverse_iterator rend(headers->rend()), rbegin(headers->rbegin()); ensure("Empty container has equal rbegin/rend const iterators", rend == rbegin); @@ -421,7 +420,7 @@ void HttpHeadersTestObjectType::test<6>() } // release the implicit reference, causing the object to be released - headers->release(); + headers.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); diff --git a/indra/llcorehttp/tests/test_httprequest.hpp b/indra/llcorehttp/tests/test_httprequest.hpp index 43f7e36da5..1f606bd0c1 100755 --- a/indra/llcorehttp/tests/test_httprequest.hpp +++ b/indra/llcorehttp/tests/test_httprequest.hpp @@ -112,7 +112,7 @@ public: if (! mHeadersRequired.empty() || ! mHeadersDisallowed.empty()) { ensure("Response required with header check", response != NULL); - HttpHeaders * header(response->getHeaders()); // Will not hold onto this + HttpHeaders::ptr_t header(response->getHeaders()); // Will not hold onto this ensure("Some quantity of headers returned", header != NULL); if (! mHeadersRequired.empty()) @@ -638,7 +638,7 @@ void HttpRequestTestObjectType::test<7>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * opts = NULL; + HttpOptions::ptr_t opts; try { @@ -653,7 +653,7 @@ void HttpRequestTestObjectType::test<7>() req = new HttpRequest(); ensure("Memory allocated on construction", mMemTotal < GetMemTotal()); - opts = new HttpOptions(); + opts = HttpOptions::ptr_t(new HttpOptions()); opts->setRetries(1); // Don't try for too long - default retries take about 18S // Issue a GET that can't connect @@ -664,7 +664,7 @@ void HttpRequestTestObjectType::test<7>() 0, 0, opts, - NULL, + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); @@ -705,8 +705,7 @@ void HttpRequestTestObjectType::test<7>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options - opts->release(); - opts = NULL; + opts.reset(); // release the request object delete req; @@ -728,11 +727,7 @@ void HttpRequestTestObjectType::test<7>() catch (...) { stop_thread(req); - if (opts) - { - opts->release(); - opts = NULL; - } + opts.reset(); delete req; HttpRequest::destroyService(); throw; @@ -779,8 +774,8 @@ void HttpRequestTestObjectType::test<8>() HttpHandle handle = req->requestGet(HttpRequest::DEFAULT_POLICY_ID, 0U, url_base, - NULL, - NULL, + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); @@ -889,8 +884,8 @@ void HttpRequestTestObjectType::test<9>() url_base, 0, 0, - NULL, - NULL, + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); @@ -1001,9 +996,9 @@ void HttpRequestTestObjectType::test<10>() 0U, url_base, body, - NULL, - NULL, - &handler); + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // Run the notification pump. @@ -1119,9 +1114,9 @@ void HttpRequestTestObjectType::test<11>() 0U, url_base, body, - NULL, - NULL, - &handler); + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // Run the notification pump. @@ -1239,9 +1234,9 @@ void HttpRequestTestObjectType::test<12>() url_base, 0, 0, - NULL, - NULL, - &handler); + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // Run the notification pump. @@ -1332,7 +1327,7 @@ void HttpRequestTestObjectType::test<13>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * opts = NULL; + HttpOptions::ptr_t opts; try { @@ -1350,7 +1345,7 @@ void HttpRequestTestObjectType::test<13>() req = new HttpRequest(); ensure("Memory allocated on construction", mMemTotal < GetMemTotal()); - opts = new HttpOptions(); + opts = HttpOptions::ptr_t(new HttpOptions()); opts->setWantHeaders(true); // Issue a GET that succeeds @@ -1364,13 +1359,12 @@ void HttpRequestTestObjectType::test<13>() 0, 0, opts, - NULL, - &handler); + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // release options - opts->release(); - opts = NULL; + opts.reset(); // Run the notification pump. int count(0); @@ -1430,11 +1424,7 @@ void HttpRequestTestObjectType::test<13>() catch (...) { stop_thread(req); - if (opts) - { - opts->release(); - opts = NULL; - } + opts.reset(); delete req; HttpRequest::destroyService(); throw; @@ -1460,7 +1450,7 @@ void HttpRequestTestObjectType::test<14>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * opts = NULL; + HttpOptions::ptr_t opts; try { @@ -1475,7 +1465,7 @@ void HttpRequestTestObjectType::test<14>() req = new HttpRequest(); ensure("Memory allocated on construction", mMemTotal < GetMemTotal()); - opts = new HttpOptions(); + opts = HttpOptions::ptr_t(new HttpOptions); opts->setRetries(0); // Don't retry opts->setTimeout(2); @@ -1487,8 +1477,8 @@ void HttpRequestTestObjectType::test<14>() 0, 0, opts, - NULL, - &handler); + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // Run the notification pump. @@ -1528,8 +1518,7 @@ void HttpRequestTestObjectType::test<14>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options - opts->release(); - opts = NULL; + opts.reset(); // release the request object delete req; @@ -1552,11 +1541,7 @@ void HttpRequestTestObjectType::test<14>() catch (...) { stop_thread(req); - if (opts) - { - opts->release(); - opts = NULL; - } + opts.reset(); delete req; HttpRequest::destroyService(); throw; @@ -1609,9 +1594,9 @@ void HttpRequestTestObjectType::test<15>() HttpHandle handle = req->requestGet(HttpRequest::DEFAULT_POLICY_ID, 0U, url_base, - NULL, - NULL, - &handler); + HttpOptions::ptr_t(), + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); // Run the notification pump. @@ -1703,8 +1688,8 @@ void HttpRequestTestObjectType::test<16>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; try { @@ -1719,7 +1704,7 @@ void HttpRequestTestObjectType::test<16>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // Issue a GET that *can* connect @@ -1776,7 +1761,7 @@ void HttpRequestTestObjectType::test<16>() 0U, url_base + "reflect/", options, - NULL, + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for get request", handle != LLCORE_HTTP_HANDLE_INVALID); @@ -1792,7 +1777,7 @@ void HttpRequestTestObjectType::test<16>() ensure("One handler invocation for request", mHandlerCalls == 1); // Do a texture-style fetch - headers = new HttpHeaders; + headers = HttpHeaders::ptr_t(new HttpHeaders); headers->append("Accept", "image/x-j2c"); mStatus = HttpStatus(200); @@ -1897,17 +1882,8 @@ void HttpRequestTestObjectType::test<16>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -1919,16 +1895,9 @@ void HttpRequestTestObjectType::test<16>() catch (...) { stop_thread(req); - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } + options.reset(); + headers.reset(); + delete req; HttpRequest::destroyService(); throw; @@ -1960,8 +1929,8 @@ void HttpRequestTestObjectType::test<17>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; BufferArray * ba = NULL; try @@ -1977,7 +1946,7 @@ void HttpRequestTestObjectType::test<17>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // And a buffer array @@ -2049,7 +2018,7 @@ void HttpRequestTestObjectType::test<17>() url_base + "reflect/", ba, options, - NULL, + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for get request", handle != LLCORE_HTTP_HANDLE_INVALID); ba->release(); @@ -2095,17 +2064,8 @@ void HttpRequestTestObjectType::test<17>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -2122,17 +2082,10 @@ void HttpRequestTestObjectType::test<17>() ba->release(); ba = NULL; } - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } - delete req; + options.reset(); + headers.reset(); + + delete req; HttpRequest::destroyService(); throw; } @@ -2163,8 +2116,8 @@ void HttpRequestTestObjectType::test<18>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; BufferArray * ba = NULL; try @@ -2180,7 +2133,7 @@ void HttpRequestTestObjectType::test<18>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // And a buffer array @@ -2253,7 +2206,7 @@ void HttpRequestTestObjectType::test<18>() url_base + "reflect/", ba, options, - NULL, + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for get request", handle != LLCORE_HTTP_HANDLE_INVALID); ba->release(); @@ -2299,17 +2252,8 @@ void HttpRequestTestObjectType::test<18>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -2326,17 +2270,10 @@ void HttpRequestTestObjectType::test<18>() ba->release(); ba = NULL; } - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } - delete req; + options.reset(); + headers.reset(); + + delete req; HttpRequest::destroyService(); throw; } @@ -2367,8 +2304,8 @@ void HttpRequestTestObjectType::test<19>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; try { @@ -2383,11 +2320,11 @@ void HttpRequestTestObjectType::test<19>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // headers - headers = new HttpHeaders; + headers = HttpHeaders::ptr_t(new HttpHeaders); headers->append("Keep-Alive", "120"); headers->append("Accept-encoding", "deflate"); headers->append("Accept", "text/plain"); @@ -2502,17 +2439,8 @@ void HttpRequestTestObjectType::test<19>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -2524,16 +2452,9 @@ void HttpRequestTestObjectType::test<19>() catch (...) { stop_thread(req); - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } + options.reset(); + headers.reset(); + delete req; HttpRequest::destroyService(); throw; @@ -2565,8 +2486,8 @@ void HttpRequestTestObjectType::test<20>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; BufferArray * ba = NULL; try @@ -2582,11 +2503,11 @@ void HttpRequestTestObjectType::test<20>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // headers - headers = new HttpHeaders(); + headers = HttpHeaders::ptr_t(new HttpHeaders()); headers->append("keep-Alive", "120"); headers->append("Accept", "text/html"); headers->append("content-type", "application/llsd+xml"); @@ -2720,17 +2641,8 @@ void HttpRequestTestObjectType::test<20>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -2747,16 +2659,8 @@ void HttpRequestTestObjectType::test<20>() ba->release(); ba = NULL; } - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } + options.reset(); + headers.reset(); delete req; HttpRequest::destroyService(); throw; @@ -2788,8 +2692,8 @@ void HttpRequestTestObjectType::test<21>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * options = NULL; - HttpHeaders * headers = NULL; + HttpOptions::ptr_t options; + HttpHeaders::ptr_t headers; BufferArray * ba = NULL; try @@ -2805,11 +2709,11 @@ void HttpRequestTestObjectType::test<21>() req = new HttpRequest(); // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setWantHeaders(true); // headers - headers = new HttpHeaders; + headers = HttpHeaders::ptr_t(new HttpHeaders); headers->append("content-type", "text/plain"); headers->append("content-type", "text/html"); headers->append("content-type", "application/llsd+xml"); @@ -2937,17 +2841,8 @@ void HttpRequestTestObjectType::test<21>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options & headers - if (options) - { - options->release(); - } - options = NULL; - - if (headers) - { - headers->release(); - } - headers = NULL; + options.reset(); + headers.reset(); // release the request object delete req; @@ -2964,16 +2859,8 @@ void HttpRequestTestObjectType::test<21>() ba->release(); ba = NULL; } - if (options) - { - options->release(); - options = NULL; - } - if (headers) - { - headers->release(); - headers = NULL; - } + options.reset(); + headers.reset(); delete req; HttpRequest::destroyService(); throw; @@ -3000,13 +2887,13 @@ void HttpRequestTestObjectType::test<22>() mMemTotal = GetMemTotal(); mHandlerCalls = 0; - HttpOptions * options = NULL; + HttpOptions::ptr_t options; HttpRequest * req = NULL; try { // options set - options = new HttpOptions(); + options = HttpOptions::ptr_t(new HttpOptions()); options->setRetries(1); // Partial_File is retryable and can timeout in here // Get singletons created @@ -3035,8 +2922,8 @@ void HttpRequestTestObjectType::test<22>() 0, 25, options, - NULL, - &handler); + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); } @@ -3067,7 +2954,7 @@ void HttpRequestTestObjectType::test<22>() 0, 25, options, - NULL, + HttpHeaders::ptr_t(), &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); } @@ -3099,8 +2986,8 @@ void HttpRequestTestObjectType::test<22>() 0, 25, options, - NULL, - &handler); + HttpHeaders::ptr_t(), + &handler); ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); } @@ -3144,11 +3031,7 @@ void HttpRequestTestObjectType::test<22>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options - if (options) - { - options->release(); - options = NULL; - } + options.reset(); // release the request object delete req; @@ -3198,7 +3081,7 @@ void HttpRequestTestObjectType::test<23>() mHandlerCalls = 0; HttpRequest * req = NULL; - HttpOptions * opts = NULL; + HttpOptions::ptr_t opts; try { @@ -3213,7 +3096,7 @@ void HttpRequestTestObjectType::test<23>() req = new HttpRequest(); ensure("Memory allocated on construction", mMemTotal < GetMemTotal()); - opts = new HttpOptions(); + opts = HttpOptions::ptr_t(new HttpOptions()); opts->setRetries(1); // Retry once only opts->setUseRetryAfter(true); // Try to parse the retry-after header @@ -3230,8 +3113,8 @@ void HttpRequestTestObjectType::test<23>() 0, 0, opts, - NULL, - &handler); + HttpHeaders::ptr_t(), + &handler); std::ostringstream testtag; testtag << "Valid handle returned for 503 request #" << i; @@ -3277,8 +3160,7 @@ void HttpRequestTestObjectType::test<23>() ensure("Thread actually stopped running", HttpService::isStopped()); // release options - opts->release(); - opts = NULL; + opts.reset(); // release the request object delete req; @@ -3299,11 +3181,7 @@ void HttpRequestTestObjectType::test<23>() catch (...) { stop_thread(req); - if (opts) - { - opts->release(); - opts = NULL; - } + opts.reset(); delete req; HttpRequest::destroyService(); throw; |