diff options
Diffstat (limited to 'indra/llcorehttp')
62 files changed, 501 insertions, 215 deletions
diff --git a/indra/llcorehttp/CMakeLists.txt b/indra/llcorehttp/CMakeLists.txt index 9adfd0ed62..9adfd0ed62 100644..100755 --- a/indra/llcorehttp/CMakeLists.txt +++ b/indra/llcorehttp/CMakeLists.txt diff --git a/indra/llcorehttp/_httpinternal.h b/indra/llcorehttp/_httpinternal.h index 14f744a9f1..008e4fd95c 100644..100755 --- a/indra/llcorehttp/_httpinternal.h +++ b/indra/llcorehttp/_httpinternal.h @@ -146,9 +146,6 @@ const int HTTP_SERVICE_LOOP_SLEEP_NORMAL_MS = 2; // Block allocation size (a tuning parameter) is found // in bufferarray.h. -// Compatibility controls -const bool HTTP_ENABLE_LINKSYS_WRT54G_V5_DNS_FIX = true; - } // end namespace LLCore #endif // _LLCORE_HTTP_INTERNAL_H_ diff --git a/indra/llcorehttp/_httplibcurl.cpp b/indra/llcorehttp/_httplibcurl.cpp index 6fe0bfc7d1..6fe0bfc7d1 100644..100755 --- a/indra/llcorehttp/_httplibcurl.cpp +++ b/indra/llcorehttp/_httplibcurl.cpp diff --git a/indra/llcorehttp/_httplibcurl.h b/indra/llcorehttp/_httplibcurl.h index 611f029ef5..611f029ef5 100644..100755 --- a/indra/llcorehttp/_httplibcurl.h +++ b/indra/llcorehttp/_httplibcurl.h diff --git a/indra/llcorehttp/_httpopcancel.cpp b/indra/llcorehttp/_httpopcancel.cpp index c1912eb3db..c1912eb3db 100644..100755 --- a/indra/llcorehttp/_httpopcancel.cpp +++ b/indra/llcorehttp/_httpopcancel.cpp diff --git a/indra/llcorehttp/_httpopcancel.h b/indra/llcorehttp/_httpopcancel.h index 336dfdc573..336dfdc573 100644..100755 --- a/indra/llcorehttp/_httpopcancel.h +++ b/indra/llcorehttp/_httpopcancel.h diff --git a/indra/llcorehttp/_httpoperation.cpp b/indra/llcorehttp/_httpoperation.cpp index 5cf5bc5930..5cf5bc5930 100644..100755 --- a/indra/llcorehttp/_httpoperation.cpp +++ b/indra/llcorehttp/_httpoperation.cpp diff --git a/indra/llcorehttp/_httpoperation.h b/indra/llcorehttp/_httpoperation.h index 914627fad0..914627fad0 100644..100755 --- a/indra/llcorehttp/_httpoperation.h +++ b/indra/llcorehttp/_httpoperation.h diff --git a/indra/llcorehttp/_httpoprequest.cpp b/indra/llcorehttp/_httpoprequest.cpp index 7db19b1841..207ed8e1e4 100644..100755 --- a/indra/llcorehttp/_httpoprequest.cpp +++ b/indra/llcorehttp/_httpoprequest.cpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -186,9 +186,11 @@ void HttpOpRequest::stageFromActive(HttpService * service) if (mReplyLength) { // If non-zero, we received and processed a Content-Range - // header with the response. Verify that what it says - // is consistent with the received data. - if (mReplyLength != mReplyBody->size()) + // header with the response. If there is received data + // (and there may not be due to protocol violations, + // HEAD requests, etc., see BUG-2295) Verify that what it + // says is consistent with the received data. + if (mReplyBody && mReplyBody->size() && mReplyLength != mReplyBody->size()) { // Not as expected, fail the request mStatus = HttpStatus(HttpStatus::LLCORE, HE_INV_CONTENT_RANGE_HDR); @@ -339,7 +341,6 @@ void HttpOpRequest::setupCommon(HttpRequest::policy_t policy_id, } } - // Sets all libcurl options and data for a request. // // Used both for initial requests and to 'reload' for @@ -381,41 +382,15 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) // Get policy options HttpPolicyGlobal & policy(service->getPolicy().getGlobalOptions()); - mCurlHandle = curl_easy_init(); - curl_easy_setopt(mCurlHandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_easy_setopt(mCurlHandle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(mCurlHandle, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(mCurlHandle, CURLOPT_URL, mReqURL.c_str()); - curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, this); - curl_easy_setopt(mCurlHandle, CURLOPT_ENCODING, ""); + mCurlHandle = LLCurl::createStandardCurlHandle(); - if (HTTP_ENABLE_LINKSYS_WRT54G_V5_DNS_FIX) - { - // The Linksys WRT54G V5 router has an issue with frequent - // DNS lookups from LAN machines. If they happen too often, - // like for every HTTP request, the router gets annoyed after - // about 700 or so requests and starts issuing TCP RSTs to - // new connections. Reuse the DNS lookups for even a few - // seconds and no RSTs. - curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 15); - } - else - { - // *TODO: Revisit this old DNS timeout setting - may no longer be valid - // I don't think this is valid anymore, the Multi shared DNS - // cache is working well. For the case of naked easy handles, - // consider using a shared DNS object. - curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0); - } - curl_easy_setopt(mCurlHandle, CURLOPT_AUTOREFERER, 1); - curl_easy_setopt(mCurlHandle, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(mCurlHandle, CURLOPT_MAXREDIRS, HTTP_REDIRECTS_DEFAULT); curl_easy_setopt(mCurlHandle, CURLOPT_WRITEFUNCTION, writeCallback); - curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, this); - curl_easy_setopt(mCurlHandle, CURLOPT_READFUNCTION, readCallback); + curl_easy_setopt(mCurlHandle, CURLOPT_READFUNCTION, readCallback); curl_easy_setopt(mCurlHandle, CURLOPT_READDATA, this); - curl_easy_setopt(mCurlHandle, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(mCurlHandle, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, this); + curl_easy_setopt(mCurlHandle, CURLOPT_URL, mReqURL.c_str()); + curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, this); + curl_easy_setopt(mCurlHandle, CURLOPT_MAXREDIRS, HTTP_REDIRECTS_DEFAULT); const std::string * opt_value(NULL); long opt_long(0L); @@ -580,8 +555,13 @@ size_t HttpOpRequest::readCallback(void * data, size_t size, size_t nmemb, void const size_t body_size(op->mReqBody->size()); if (body_size <= op->mCurlBodyPos) { - LL_WARNS("HttpCore") << "Request body position beyond body size. Aborting request." - << LL_ENDL; + if (body_size < op->mCurlBodyPos) + { + // Warn but continue if the read position moves beyond end-of-body + // for some reason. + LL_WARNS("HttpCore") << "Request body position beyond body size. Truncating request body." + << LL_ENDL; + } return 0; } @@ -689,7 +669,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe std::string safe_line; std::string tag; bool logit(false); - len = (std::min)(len, size_t(256)); // Keep things reasonable in all cases + const size_t log_len((std::min)(len, size_t(256))); // Keep things reasonable in all cases switch (info) { @@ -697,7 +677,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe if (op->mTracing >= HTTP_TRACE_CURL_HEADERS) { tag = "TEXT"; - escape_libcurl_debug_data(buffer, len, true, safe_line); + escape_libcurl_debug_data(buffer, log_len, true, safe_line); logit = true; } break; @@ -706,7 +686,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe if (op->mTracing >= HTTP_TRACE_CURL_HEADERS) { tag = "HEADERIN"; - escape_libcurl_debug_data(buffer, len, true, safe_line); + escape_libcurl_debug_data(buffer, log_len, true, safe_line); logit = true; } break; @@ -715,7 +695,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe if (op->mTracing >= HTTP_TRACE_CURL_HEADERS) { tag = "HEADEROUT"; - escape_libcurl_debug_data(buffer, 2 * len, true, safe_line); // Goes out as one line + escape_libcurl_debug_data(buffer, log_len, true, safe_line); // Goes out as one line unlike header_in logit = true; } break; @@ -727,7 +707,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe logit = true; if (op->mTracing >= HTTP_TRACE_CURL_BODIES) { - escape_libcurl_debug_data(buffer, len, false, safe_line); + escape_libcurl_debug_data(buffer, log_len, false, safe_line); } else { @@ -745,7 +725,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe logit = true; if (op->mTracing >= HTTP_TRACE_CURL_BODIES) { - escape_libcurl_debug_data(buffer, len, false, safe_line); + escape_libcurl_debug_data(buffer, log_len, false, safe_line); } else { diff --git a/indra/llcorehttp/_httpoprequest.h b/indra/llcorehttp/_httpoprequest.h index 7b65d17783..74a349b0bf 100644..100755 --- a/indra/llcorehttp/_httpoprequest.h +++ b/indra/llcorehttp/_httpoprequest.h @@ -60,7 +60,6 @@ class HttpOptions; /// the information needed to make a working request which can /// then be enqueued to a request queue. /// - class HttpOpRequest : public HttpOperation { public: diff --git a/indra/llcorehttp/_httpopsetget.cpp b/indra/llcorehttp/_httpopsetget.cpp index 8198528a9b..8198528a9b 100644..100755 --- a/indra/llcorehttp/_httpopsetget.cpp +++ b/indra/llcorehttp/_httpopsetget.cpp diff --git a/indra/llcorehttp/_httpopsetget.h b/indra/llcorehttp/_httpopsetget.h index 6966b9d94e..6966b9d94e 100644..100755 --- a/indra/llcorehttp/_httpopsetget.h +++ b/indra/llcorehttp/_httpopsetget.h diff --git a/indra/llcorehttp/_httpopsetpriority.cpp b/indra/llcorehttp/_httpopsetpriority.cpp index d48c7a0b7d..d48c7a0b7d 100644..100755 --- a/indra/llcorehttp/_httpopsetpriority.cpp +++ b/indra/llcorehttp/_httpopsetpriority.cpp diff --git a/indra/llcorehttp/_httpopsetpriority.h b/indra/llcorehttp/_httpopsetpriority.h index 31706b737c..31706b737c 100644..100755 --- a/indra/llcorehttp/_httpopsetpriority.h +++ b/indra/llcorehttp/_httpopsetpriority.h diff --git a/indra/llcorehttp/_httppolicy.cpp b/indra/llcorehttp/_httppolicy.cpp index 76c1e22431..014bd37e2e 100644..100755 --- a/indra/llcorehttp/_httppolicy.cpp +++ b/indra/llcorehttp/_httppolicy.cpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -319,33 +319,13 @@ bool HttpPolicy::cancel(HttpHandle handle) bool HttpPolicy::stageAfterCompletion(HttpOpRequest * op) { - static const HttpStatus cant_connect(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_CONNECT); - static const HttpStatus cant_res_proxy(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_PROXY); - static const HttpStatus cant_res_host(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_HOST); - static const HttpStatus send_error(HttpStatus::EXT_CURL_EASY, CURLE_SEND_ERROR); - static const HttpStatus recv_error(HttpStatus::EXT_CURL_EASY, CURLE_RECV_ERROR); - static const HttpStatus upload_failed(HttpStatus::EXT_CURL_EASY, CURLE_UPLOAD_FAILED); - static const HttpStatus op_timedout(HttpStatus::EXT_CURL_EASY, CURLE_OPERATION_TIMEDOUT); - static const HttpStatus post_error(HttpStatus::EXT_CURL_EASY, CURLE_HTTP_POST_ERROR); - // Retry or finalize if (! op->mStatus) { - // If this failed, we might want to retry. Have to inspect - // the status a little more deeply for those reasons worth retrying... - if (op->mPolicyRetries < op->mPolicyRetryLimit && - ((op->mStatus.isHttpStatus() && op->mStatus.mType >= 499 && op->mStatus.mType <= 599) || - cant_connect == op->mStatus || - cant_res_proxy == op->mStatus || - cant_res_host == op->mStatus || - send_error == op->mStatus || - recv_error == op->mStatus || - upload_failed == op->mStatus || - op_timedout == op->mStatus || - post_error == op->mStatus)) + // If this failed, we might want to retry. + if (op->mPolicyRetries < op->mPolicyRetryLimit && op->mStatus.isRetryable()) { - // Okay, worth a retry. We include 499 in this test as - // it's the old 'who knows?' error from many grid services... + // Okay, worth a retry. retryOp(op); return true; // still active/ready } diff --git a/indra/llcorehttp/_httppolicy.h b/indra/llcorehttp/_httppolicy.h index 03d92c0b8e..03d92c0b8e 100644..100755 --- a/indra/llcorehttp/_httppolicy.h +++ b/indra/llcorehttp/_httppolicy.h diff --git a/indra/llcorehttp/_httppolicyclass.cpp b/indra/llcorehttp/_httppolicyclass.cpp index a23b81322c..a23b81322c 100644..100755 --- a/indra/llcorehttp/_httppolicyclass.cpp +++ b/indra/llcorehttp/_httppolicyclass.cpp diff --git a/indra/llcorehttp/_httppolicyclass.h b/indra/llcorehttp/_httppolicyclass.h index d175413cbd..d175413cbd 100644..100755 --- a/indra/llcorehttp/_httppolicyclass.h +++ b/indra/llcorehttp/_httppolicyclass.h diff --git a/indra/llcorehttp/_httppolicyglobal.cpp b/indra/llcorehttp/_httppolicyglobal.cpp index 72f409d3b1..72f409d3b1 100644..100755 --- a/indra/llcorehttp/_httppolicyglobal.cpp +++ b/indra/llcorehttp/_httppolicyglobal.cpp diff --git a/indra/llcorehttp/_httppolicyglobal.h b/indra/llcorehttp/_httppolicyglobal.h index a50d0e4188..a50d0e4188 100644..100755 --- a/indra/llcorehttp/_httppolicyglobal.h +++ b/indra/llcorehttp/_httppolicyglobal.h diff --git a/indra/llcorehttp/_httpreadyqueue.h b/indra/llcorehttp/_httpreadyqueue.h index 5f19a9c5f9..5f19a9c5f9 100644..100755 --- a/indra/llcorehttp/_httpreadyqueue.h +++ b/indra/llcorehttp/_httpreadyqueue.h diff --git a/indra/llcorehttp/_httpreplyqueue.cpp b/indra/llcorehttp/_httpreplyqueue.cpp index 558b7bdee9..558b7bdee9 100644..100755 --- a/indra/llcorehttp/_httpreplyqueue.cpp +++ b/indra/llcorehttp/_httpreplyqueue.cpp diff --git a/indra/llcorehttp/_httpreplyqueue.h b/indra/llcorehttp/_httpreplyqueue.h index 4220a09a3b..4220a09a3b 100644..100755 --- a/indra/llcorehttp/_httpreplyqueue.h +++ b/indra/llcorehttp/_httpreplyqueue.h diff --git a/indra/llcorehttp/_httprequestqueue.cpp b/indra/llcorehttp/_httprequestqueue.cpp index c16966d078..c16966d078 100644..100755 --- a/indra/llcorehttp/_httprequestqueue.cpp +++ b/indra/llcorehttp/_httprequestqueue.cpp diff --git a/indra/llcorehttp/_httprequestqueue.h b/indra/llcorehttp/_httprequestqueue.h index c9c52b7233..c9c52b7233 100644..100755 --- a/indra/llcorehttp/_httprequestqueue.h +++ b/indra/llcorehttp/_httprequestqueue.h diff --git a/indra/llcorehttp/_httpretryqueue.h b/indra/llcorehttp/_httpretryqueue.h index 745adec09d..745adec09d 100644..100755 --- a/indra/llcorehttp/_httpretryqueue.h +++ b/indra/llcorehttp/_httpretryqueue.h diff --git a/indra/llcorehttp/_httpservice.cpp b/indra/llcorehttp/_httpservice.cpp index 0825888d0f..0825888d0f 100644..100755 --- a/indra/llcorehttp/_httpservice.cpp +++ b/indra/llcorehttp/_httpservice.cpp diff --git a/indra/llcorehttp/_httpservice.h b/indra/llcorehttp/_httpservice.h index ffe0349d4d..ffe0349d4d 100644..100755 --- a/indra/llcorehttp/_httpservice.h +++ b/indra/llcorehttp/_httpservice.h diff --git a/indra/llcorehttp/_mutex.h b/indra/llcorehttp/_mutex.h index 4be4d016d4..4be4d016d4 100644..100755 --- a/indra/llcorehttp/_mutex.h +++ b/indra/llcorehttp/_mutex.h diff --git a/indra/llcorehttp/_refcounted.cpp b/indra/llcorehttp/_refcounted.cpp index e7d0b72741..e7d0b72741 100644..100755 --- a/indra/llcorehttp/_refcounted.cpp +++ b/indra/llcorehttp/_refcounted.cpp diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h index 21a916b13b..21a916b13b 100644..100755 --- a/indra/llcorehttp/_refcounted.h +++ b/indra/llcorehttp/_refcounted.h diff --git a/indra/llcorehttp/_thread.h b/indra/llcorehttp/_thread.h index e058d660e5..e058d660e5 100644..100755 --- a/indra/llcorehttp/_thread.h +++ b/indra/llcorehttp/_thread.h diff --git a/indra/llcorehttp/bufferarray.cpp b/indra/llcorehttp/bufferarray.cpp index 8eaaeed710..8eaaeed710 100644..100755 --- a/indra/llcorehttp/bufferarray.cpp +++ b/indra/llcorehttp/bufferarray.cpp diff --git a/indra/llcorehttp/bufferarray.h b/indra/llcorehttp/bufferarray.h index 1094a435b4..1094a435b4 100644..100755 --- a/indra/llcorehttp/bufferarray.h +++ b/indra/llcorehttp/bufferarray.h diff --git a/indra/llcorehttp/bufferstream.cpp b/indra/llcorehttp/bufferstream.cpp index 6553900eef..6553900eef 100644..100755 --- a/indra/llcorehttp/bufferstream.cpp +++ b/indra/llcorehttp/bufferstream.cpp diff --git a/indra/llcorehttp/bufferstream.h b/indra/llcorehttp/bufferstream.h index 9327a798aa..9327a798aa 100644..100755 --- a/indra/llcorehttp/bufferstream.h +++ b/indra/llcorehttp/bufferstream.h diff --git a/indra/llcorehttp/examples/http_texture_load.cpp b/indra/llcorehttp/examples/http_texture_load.cpp index 40ad4f047d..40ad4f047d 100644..100755 --- a/indra/llcorehttp/examples/http_texture_load.cpp +++ b/indra/llcorehttp/examples/http_texture_load.cpp diff --git a/indra/llcorehttp/httpcommon.cpp b/indra/llcorehttp/httpcommon.cpp index f2fcbf77a3..0738760763 100644..100755 --- a/indra/llcorehttp/httpcommon.cpp +++ b/indra/llcorehttp/httpcommon.cpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -116,6 +116,7 @@ std::string HttpStatus::toString() const { 415, "Unsupported Media Type" }, { 416, "Requested range not satisfiable" }, { 417, "Expectation Failed" }, + { 499, "Linden Catch-All" }, { 500, "Internal Server Error" }, { 501, "Not Implemented" }, { 502, "Bad Gateway" }, @@ -174,6 +175,37 @@ std::string HttpStatus::toString() const } return std::string("Unknown error"); } + + +// Pass true on statuses that might actually be cleared by a +// retry. Library failures, calling problems, etc. aren't +// going to be fixed by squirting bits all over the Net. +bool HttpStatus::isRetryable() const +{ + static const HttpStatus cant_connect(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_CONNECT); + static const HttpStatus cant_res_proxy(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_PROXY); + static const HttpStatus cant_res_host(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_HOST); + static const HttpStatus send_error(HttpStatus::EXT_CURL_EASY, CURLE_SEND_ERROR); + static const HttpStatus recv_error(HttpStatus::EXT_CURL_EASY, CURLE_RECV_ERROR); + static const HttpStatus upload_failed(HttpStatus::EXT_CURL_EASY, CURLE_UPLOAD_FAILED); + static const HttpStatus op_timedout(HttpStatus::EXT_CURL_EASY, CURLE_OPERATION_TIMEDOUT); + static const HttpStatus post_error(HttpStatus::EXT_CURL_EASY, CURLE_HTTP_POST_ERROR); + static const HttpStatus partial_file(HttpStatus::EXT_CURL_EASY, CURLE_PARTIAL_FILE); + static const HttpStatus inv_cont_range(HttpStatus::LLCORE, HE_INV_CONTENT_RANGE_HDR); + + return ((isHttpStatus() && mType >= 499 && mType <= 599) || // Include special 499 in retryables + *this == cant_connect || // Connection reset/endpoint problems + *this == cant_res_proxy || // DNS problems + *this == cant_res_host || // DNS problems + *this == send_error || // General socket problems + *this == recv_error || // General socket problems + *this == upload_failed || // Transport problem + *this == op_timedout || // Timer expired + *this == post_error || // Transport problem + *this == partial_file || // Data inconsistency in response + *this == inv_cont_range); // Short data read disagrees with content-range +} + } // end namespace LLCore diff --git a/indra/llcorehttp/httpcommon.h b/indra/llcorehttp/httpcommon.h index c0d4ec5aad..41fb5164cf 100644..100755 --- a/indra/llcorehttp/httpcommon.h +++ b/indra/llcorehttp/httpcommon.h @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -303,6 +303,12 @@ struct HttpStatus { return mType >= type_enum_t(100) && mType <= type_enum_t(999); } + + /// Returns true if the status is one that will be retried + /// internally. Provided for external consumption for cases + /// where that logic needs to be replicated. Only applies + /// to failed statuses, successful statuses will return false. + bool isRetryable() const; }; // end struct HttpStatus diff --git a/indra/llcorehttp/httphandler.h b/indra/llcorehttp/httphandler.h index 9171e4e7b9..9171e4e7b9 100644..100755 --- a/indra/llcorehttp/httphandler.h +++ b/indra/llcorehttp/httphandler.h diff --git a/indra/llcorehttp/httpheaders.cpp b/indra/llcorehttp/httpheaders.cpp index 2832696271..2832696271 100644..100755 --- a/indra/llcorehttp/httpheaders.cpp +++ b/indra/llcorehttp/httpheaders.cpp diff --git a/indra/llcorehttp/httpheaders.h b/indra/llcorehttp/httpheaders.h index 3449daa3a1..3449daa3a1 100644..100755 --- a/indra/llcorehttp/httpheaders.h +++ b/indra/llcorehttp/httpheaders.h diff --git a/indra/llcorehttp/httpoptions.cpp b/indra/llcorehttp/httpoptions.cpp index 1699d19f8d..1699d19f8d 100644..100755 --- a/indra/llcorehttp/httpoptions.cpp +++ b/indra/llcorehttp/httpoptions.cpp diff --git a/indra/llcorehttp/httpoptions.h b/indra/llcorehttp/httpoptions.h index 97e46a8cd3..97e46a8cd3 100644..100755 --- a/indra/llcorehttp/httpoptions.h +++ b/indra/llcorehttp/httpoptions.h diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp index 9b739a8825..9b739a8825 100644..100755 --- a/indra/llcorehttp/httprequest.cpp +++ b/indra/llcorehttp/httprequest.cpp diff --git a/indra/llcorehttp/httprequest.h b/indra/llcorehttp/httprequest.h index ab2f302d34..ab2f302d34 100644..100755 --- a/indra/llcorehttp/httprequest.h +++ b/indra/llcorehttp/httprequest.h diff --git a/indra/llcorehttp/httpresponse.cpp b/indra/llcorehttp/httpresponse.cpp index a552e48a1b..a552e48a1b 100644..100755 --- a/indra/llcorehttp/httpresponse.cpp +++ b/indra/llcorehttp/httpresponse.cpp diff --git a/indra/llcorehttp/httpresponse.h b/indra/llcorehttp/httpresponse.h index 4a481db6ac..f19b521fbf 100644..100755 --- a/indra/llcorehttp/httpresponse.h +++ b/indra/llcorehttp/httpresponse.h @@ -48,8 +48,9 @@ class HttpHeaders; /// individual pieces of the response. /// /// Typical usage will have the caller interrogate the object -/// and return from the handler callback. Instances are refcounted -/// and callers can bump the count and retain the object as needed. +/// during the handler callback and then simply returning. +/// But instances are refcounted and and callers can add a +/// reference and hold onto the object after the callback. /// /// Threading: Not intrinsically thread-safe. /// @@ -119,6 +120,10 @@ public: /// caller is going to have to make assumptions on receipt of /// a 206 status. The @full value may also be zero in cases of /// parsing problems or a wild-carded length response. + /// + /// These values will not necessarily agree with the data in + /// the body itself (if present). The BufferArray object + /// is authoritative for actual data length. void getRange(unsigned int * offset, unsigned int * length, unsigned int * full) const { *offset = mReplyOffset; diff --git a/indra/llcorehttp/tests/llcorehttp_test.cpp b/indra/llcorehttp/tests/llcorehttp_test.cpp index e863ddd13f..e863ddd13f 100644..100755 --- a/indra/llcorehttp/tests/llcorehttp_test.cpp +++ b/indra/llcorehttp/tests/llcorehttp_test.cpp diff --git a/indra/llcorehttp/tests/llcorehttp_test.h b/indra/llcorehttp/tests/llcorehttp_test.h index a9567435ce..a9567435ce 100644..100755 --- a/indra/llcorehttp/tests/llcorehttp_test.h +++ b/indra/llcorehttp/tests/llcorehttp_test.h diff --git a/indra/llcorehttp/tests/test_allocator.cpp b/indra/llcorehttp/tests/test_allocator.cpp index ea12dc58eb..ea12dc58eb 100644..100755 --- a/indra/llcorehttp/tests/test_allocator.cpp +++ b/indra/llcorehttp/tests/test_allocator.cpp diff --git a/indra/llcorehttp/tests/test_allocator.h b/indra/llcorehttp/tests/test_allocator.h index 3572bbc5c5..3572bbc5c5 100644..100755 --- a/indra/llcorehttp/tests/test_allocator.h +++ b/indra/llcorehttp/tests/test_allocator.h diff --git a/indra/llcorehttp/tests/test_bufferarray.hpp b/indra/llcorehttp/tests/test_bufferarray.hpp index 8a2a64d970..8a2a64d970 100644..100755 --- a/indra/llcorehttp/tests/test_bufferarray.hpp +++ b/indra/llcorehttp/tests/test_bufferarray.hpp diff --git a/indra/llcorehttp/tests/test_bufferstream.hpp b/indra/llcorehttp/tests/test_bufferstream.hpp index 831c901b9d..831c901b9d 100644..100755 --- a/indra/llcorehttp/tests/test_bufferstream.hpp +++ b/indra/llcorehttp/tests/test_bufferstream.hpp diff --git a/indra/llcorehttp/tests/test_httpheaders.hpp b/indra/llcorehttp/tests/test_httpheaders.hpp index ce0d19b058..ce0d19b058 100644..100755 --- a/indra/llcorehttp/tests/test_httpheaders.hpp +++ b/indra/llcorehttp/tests/test_httpheaders.hpp diff --git a/indra/llcorehttp/tests/test_httpoperation.hpp b/indra/llcorehttp/tests/test_httpoperation.hpp index 17b1a96878..17b1a96878 100644..100755 --- a/indra/llcorehttp/tests/test_httpoperation.hpp +++ b/indra/llcorehttp/tests/test_httpoperation.hpp diff --git a/indra/llcorehttp/tests/test_httprequest.hpp b/indra/llcorehttp/tests/test_httprequest.hpp index e5488cf941..900a699887 100644..100755 --- a/indra/llcorehttp/tests/test_httprequest.hpp +++ b/indra/llcorehttp/tests/test_httprequest.hpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -45,6 +45,15 @@ using namespace LLCoreInt; +// spin/sleep waiting times for client/server exchange tests +// +// These are now fairly generous to try to get around timeout +// ('reasonable time') failures during execution on a heavily- +// loaded system where the unit test is in competition with +// other programs. +static const int LOOP_SLEEP_INTERVAL(10000); +static const int LOOP_COUNT_SHORT(500); // 5-second dwell time +static const int LOOP_COUNT_LONG(3000); // 30-second dwell time namespace { @@ -294,11 +303,11 @@ void HttpRequestTestObjectType::test<3>() // Run the notification pump. int count(0); - int limit(20); + int limit(LOOP_COUNT_SHORT); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -309,21 +318,21 @@ void HttpRequestTestObjectType::test<3>() // Run the notification pump again count = 0; - limit = 100; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -392,12 +401,12 @@ void HttpRequestTestObjectType::test<4>() // Run the notification pump. int count(0); - int limit(20); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 2) { req1->update(1000000); req2->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 2); @@ -409,22 +418,22 @@ void HttpRequestTestObjectType::test<4>() // Run the notification pump again count = 0; - limit = 100; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 3) { req1->update(1000000); req2->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 3); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -493,11 +502,11 @@ void HttpRequestTestObjectType::test<5>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_SHORT); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("NoOp notification received", mHandlerCalls == 1); @@ -569,11 +578,11 @@ void HttpRequestTestObjectType::test<6>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_SHORT); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("No notifications received", mHandlerCalls == 0); @@ -650,11 +659,11 @@ void HttpRequestTestObjectType::test<7>() // Run the notification pump. int count(0); - int limit(50); // With one retry, should fail quickish + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -666,21 +675,21 @@ void HttpRequestTestObjectType::test<7>() // Run the notification pump again count = 0; - limit = 100; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -766,11 +775,11 @@ void HttpRequestTestObjectType::test<8>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -782,21 +791,21 @@ void HttpRequestTestObjectType::test<8>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -876,11 +885,11 @@ void HttpRequestTestObjectType::test<9>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -892,21 +901,21 @@ void HttpRequestTestObjectType::test<9>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -988,11 +997,11 @@ void HttpRequestTestObjectType::test<10>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1004,21 +1013,21 @@ void HttpRequestTestObjectType::test<10>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1106,11 +1115,11 @@ void HttpRequestTestObjectType::test<11>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1122,21 +1131,21 @@ void HttpRequestTestObjectType::test<11>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1226,11 +1235,11 @@ void HttpRequestTestObjectType::test<12>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1242,21 +1251,21 @@ void HttpRequestTestObjectType::test<12>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1339,8 +1348,8 @@ void HttpRequestTestObjectType::test<13>() HttpHandle handle = req->requestGetByteRange(HttpRequest::DEFAULT_POLICY_ID, 0U, url_base, - 0, - 0, + 0, + 0, opts, NULL, &handler); @@ -1352,11 +1361,11 @@ void HttpRequestTestObjectType::test<13>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1369,21 +1378,21 @@ void HttpRequestTestObjectType::test<13>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1471,11 +1480,11 @@ void HttpRequestTestObjectType::test<14>() // Run the notification pump. int count(0); - int limit(50); // With one retry, should fail quickish + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1487,21 +1496,21 @@ void HttpRequestTestObjectType::test<14>() // Run the notification pump again count = 0; - limit = 100; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1594,11 +1603,11 @@ void HttpRequestTestObjectType::test<15>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1611,21 +1620,21 @@ void HttpRequestTestObjectType::test<15>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1724,11 +1733,11 @@ void HttpRequestTestObjectType::test<16>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1764,11 +1773,11 @@ void HttpRequestTestObjectType::test<16>() // Run the notification pump. count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 2); @@ -1783,21 +1792,21 @@ void HttpRequestTestObjectType::test<16>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 3) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 3); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -1919,11 +1928,11 @@ void HttpRequestTestObjectType::test<17>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -1938,21 +1947,21 @@ void HttpRequestTestObjectType::test<17>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -2079,11 +2088,11 @@ void HttpRequestTestObjectType::test<18>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -2098,21 +2107,21 @@ void HttpRequestTestObjectType::test<18>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -2237,11 +2246,11 @@ void HttpRequestTestObjectType::test<19>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -2255,21 +2264,21 @@ void HttpRequestTestObjectType::test<19>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -2401,11 +2410,11 @@ void HttpRequestTestObjectType::test<20>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -2420,21 +2429,21 @@ void HttpRequestTestObjectType::test<20>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -2569,11 +2578,11 @@ void HttpRequestTestObjectType::test<21>() // Run the notification pump. int count(0); - int limit(10); + int limit(LOOP_COUNT_LONG); while (count++ < limit && mHandlerCalls < 1) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Request executed in reasonable time", count < limit); ensure("One handler invocation for request", mHandlerCalls == 1); @@ -2588,21 +2597,21 @@ void HttpRequestTestObjectType::test<21>() // Run the notification pump again count = 0; - limit = 10; + limit = LOOP_COUNT_LONG; while (count++ < limit && mHandlerCalls < 2) { req->update(1000000); - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Second request executed in reasonable time", count < limit); ensure("Second handler invocation", mHandlerCalls == 2); // See that we actually shutdown the thread count = 0; - limit = 10; + limit = LOOP_COUNT_SHORT; while (count++ < limit && ! HttpService::isStopped()) { - usleep(100000); + usleep(LOOP_SLEEP_INTERVAL); } ensure("Thread actually stopped running", HttpService::isStopped()); @@ -2650,6 +2659,200 @@ void HttpRequestTestObjectType::test<21>() } } +// BUG-2295 Tests - Content-Range header received but no body +template <> template <> +void HttpRequestTestObjectType::test<22>() +{ + ScopedCurlInit ready; + + std::string url_base(get_base_url()); + // std::cerr << "Base: " << url_base << std::endl; + + set_test_name("BUG-2295"); + + // Handler can be stack-allocated *if* there are no dangling + // references to it after completion of this method. + // Create before memory record as the string copy will bump numbers. + TestHandler2 handler(this, "handler"); + + // record the total amount of dynamically allocated memory + mMemTotal = GetMemTotal(); + mHandlerCalls = 0; + + HttpOptions * options = NULL; + HttpRequest * req = NULL; + + try + { + // options set + options = new HttpOptions(); + options->setRetries(1); // Partial_File is retryable and can timeout in here + + // Get singletons created + HttpRequest::createService(); + + // Start threading early so that thread memory is invariant + // over the test. + HttpRequest::startThread(); + + // create a new ref counted object with an implicit reference + req = new HttpRequest(); + ensure("Memory allocated on construction", mMemTotal < GetMemTotal()); + + // ====================================== + // Issue bug2295 GETs that will get a 206 + // ====================================== + mStatus = HttpStatus(206); + static const int test_count(3); + for (int i(0); i < test_count; ++i) + { + char buffer[128]; + sprintf(buffer, "/bug2295/%d/", i); + HttpHandle handle = req->requestGetByteRange(HttpRequest::DEFAULT_POLICY_ID, + 0U, + url_base + buffer, + 0, + 25, + options, + NULL, + &handler); + ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); + } + + // Run the notification pump. + int count(0); + int limit(LOOP_COUNT_LONG); + while (count++ < limit && mHandlerCalls < test_count) + { + req->update(1000000); + usleep(LOOP_SLEEP_INTERVAL); + } + ensure("Request executed in reasonable time - ms1", count < limit); + ensure("One handler invocation for each request - ms1", mHandlerCalls == test_count); + + // ====================================== + // Issue bug2295 GETs that will get a libcurl 18 (PARTIAL_FILE) + // ====================================== + mHandlerCalls = 0; + mStatus = HttpStatus(HttpStatus::EXT_CURL_EASY, CURLE_PARTIAL_FILE); + static const int test2_count(1); + for (int i(0); i < test2_count; ++i) + { + char buffer[128]; + sprintf(buffer, "/bug2295/00000012/%d/", i); + HttpHandle handle = req->requestGetByteRange(HttpRequest::DEFAULT_POLICY_ID, + 0U, + url_base + buffer, + 0, + 25, + options, + NULL, + &handler); + ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); + } + + // Run the notification pump. + count = 0; + limit = LOOP_COUNT_LONG; + while (count++ < limit && mHandlerCalls < test2_count) + { + req->update(1000000); + usleep(LOOP_SLEEP_INTERVAL); + } + ensure("Request executed in reasonable time - ms2", count < limit); + ensure("One handler invocation for each request - ms2", mHandlerCalls == test2_count); + + // ====================================== + // Issue bug2295 GETs that will get an llcorehttp HE_INV_CONTENT_RANGE_HDR status + // ====================================== + mHandlerCalls = 0; + mStatus = HttpStatus(HttpStatus::LLCORE, HE_INV_CONTENT_RANGE_HDR); + static const int test3_count(1); + for (int i(0); i < test3_count; ++i) + { + char buffer[128]; + sprintf(buffer, "/bug2295/inv_cont_range/%d/", i); + HttpHandle handle = req->requestGetByteRange(HttpRequest::DEFAULT_POLICY_ID, + 0U, + url_base + buffer, + 0, + 25, + options, + NULL, + &handler); + ensure("Valid handle returned for ranged request", handle != LLCORE_HTTP_HANDLE_INVALID); + } + + // Run the notification pump. + count = 0; + limit = LOOP_COUNT_LONG; + while (count++ < limit && mHandlerCalls < test3_count) + { + req->update(1000000); + usleep(LOOP_SLEEP_INTERVAL); + } + ensure("Request executed in reasonable time - ms3", count < limit); + ensure("One handler invocation for each request - ms3", mHandlerCalls == test3_count); + + // ====================================== + // Okay, request a shutdown of the servicing thread + // ====================================== + mStatus = HttpStatus(); + mHandlerCalls = 0; + HttpHandle handle = req->requestStopThread(&handler); + ensure("Valid handle returned for second request", handle != LLCORE_HTTP_HANDLE_INVALID); + + // Run the notification pump again + count = 0; + limit = LOOP_COUNT_LONG; + while (count++ < limit && mHandlerCalls < 1) + { + req->update(1000000); + usleep(LOOP_SLEEP_INTERVAL); + } + ensure("Shutdown request executed in reasonable time", count < limit); + ensure("Shutdown handler invocation", mHandlerCalls == 1); + + // See that we actually shutdown the thread + count = 0; + limit = LOOP_COUNT_SHORT; + while (count++ < limit && ! HttpService::isStopped()) + { + usleep(LOOP_SLEEP_INTERVAL); + } + ensure("Thread actually stopped running", HttpService::isStopped()); + + // release options + if (options) + { + options->release(); + options = NULL; + } + + // release the request object + delete req; + req = NULL; + + // Shut down service + HttpRequest::destroyService(); + +#if defined(WIN32) + // Can only do this memory test on Windows. On other platforms, + // the LL logging system holds on to memory and produces what looks + // like memory leaks... + + // printf("Old mem: %d, New mem: %d\n", mMemTotal, GetMemTotal()); + ensure("Memory usage back to that at entry", mMemTotal == GetMemTotal()); +#endif + } + catch (...) + { + stop_thread(req); + delete req; + HttpRequest::destroyService(); + throw; + } +} } // end namespace tut diff --git a/indra/llcorehttp/tests/test_httprequestqueue.hpp b/indra/llcorehttp/tests/test_httprequestqueue.hpp index 1de2d8f9ab..1de2d8f9ab 100644..100755 --- a/indra/llcorehttp/tests/test_httprequestqueue.hpp +++ b/indra/llcorehttp/tests/test_httprequestqueue.hpp diff --git a/indra/llcorehttp/tests/test_httpstatus.hpp b/indra/llcorehttp/tests/test_httpstatus.hpp index f7b542d3b5..b5538528c5 100644..100755 --- a/indra/llcorehttp/tests/test_httpstatus.hpp +++ b/indra/llcorehttp/tests/test_httpstatus.hpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2012-2013, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -103,7 +103,7 @@ void HttpStatusTestObjectType::test<2>() template <> template <> void HttpStatusTestObjectType::test<3>() { - set_test_name("HttpStatus valid error string conversion"); + set_test_name("HttpStatus valid status string conversion"); HttpStatus status; status.mType = HttpStatus::EXT_CURL_EASY; @@ -135,7 +135,7 @@ void HttpStatusTestObjectType::test<3>() template <> template <> void HttpStatusTestObjectType::test<4>() { - set_test_name("HttpStatus invalid error string conversion"); + set_test_name("HttpStatus invalid status string conversion"); HttpStatus status; status.mType = HttpStatus::EXT_CURL_EASY; @@ -227,7 +227,7 @@ void HttpStatusTestObjectType::test<6>() template <> template <> void HttpStatusTestObjectType::test<7>() { - set_test_name("HttpStatus HTTP error text strings"); + set_test_name("HttpStatus HTTP status text strings"); HttpStatus status(100, HE_REPLY_ERROR); std::string msg(status.toString()); diff --git a/indra/llcorehttp/tests/test_llcorehttp_peer.py b/indra/llcorehttp/tests/test_llcorehttp_peer.py index 75a3c39ef2..3c3af8dc75 100644..100755 --- a/indra/llcorehttp/tests/test_llcorehttp_peer.py +++ b/indra/llcorehttp/tests/test_llcorehttp_peer.py @@ -9,7 +9,7 @@ $LicenseInfo:firstyear=2008&license=viewerlgpl$ Second Life Viewer Source Code -Copyright (C) 2012, Linden Research, Inc. +Copyright (C) 2012-2013, Linden Research, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -35,6 +35,10 @@ import time import select import getopt from threading import Thread +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from SocketServer import ThreadingMixIn @@ -47,7 +51,30 @@ from testrunner import freeport, run, debug, VERBOSE class TestHTTPRequestHandler(BaseHTTPRequestHandler): """This subclass of BaseHTTPRequestHandler is to receive and echo LLSD-flavored messages sent by the C++ LLHTTPClient. + + Target URLs are fairly free-form and are assembled by + concatinating fragments. Currently defined fragments + are: + - '/reflect/' Request headers are bounced back to caller + after prefixing with 'X-Reflect-' + - '/fail/' Body of request can contain LLSD with + 'reason' string and 'status' integer + which will become response header. + - '/bug2295/' 206 response, no data in body: + -- '/bug2295/0/' "Content-Range: bytes 0-75/2983" + -- '/bug2295/1/' "Content-Range: bytes 0-75/*" + -- '/bug2295/2/' "Content-Range: bytes 0-75/2983", + "Content-Length: 0" + -- '/bug2295/00000018/0/' Generates PARTIAL_FILE (18) error in libcurl. + "Content-Range: bytes 0-75/2983", + "Content-Length: 76" + -- '/bug2295/inv_cont_range/0/' Generates HE_INVALID_CONTENT_RANGE error in llcorehttp. + + Some combinations make no sense, there's no effort to protect + you from that. """ + ignore_exceptions = (Exception,) + def read(self): # The following logic is adapted from the library module # SimpleXMLRPCServer.py. @@ -87,42 +114,36 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self, withdata=True): # Of course, don't attempt to read data. - self.answer(dict(reply="success", status=200, - reason="Your GET operation worked")) + try: + self.answer(dict(reply="success", status=200, + reason="Your GET operation worked")) + except self.ignore_exceptions, e: + print >> sys.stderr, "Exception during GET (ignoring): %s" % str(e) def do_POST(self): # Read the provided POST data. # self.answer(self.read()) - self.answer(dict(reply="success", status=200, - reason=self.read())) + try: + self.answer(dict(reply="success", status=200, + reason=self.read())) + except self.ignore_exceptions, e: + print >> sys.stderr, "Exception during POST (ignoring): %s" % str(e) def do_PUT(self): # Read the provided PUT data. # self.answer(self.read()) - self.answer(dict(reply="success", status=200, - reason=self.read())) + try: + self.answer(dict(reply="success", status=200, + reason=self.read())) + except self.ignore_exceptions, e: + print >> sys.stderr, "Exception during PUT (ignoring): %s" % str(e) def answer(self, data, withdata=True): debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path) if "/sleep/" in self.path: time.sleep(30) - if "fail" not in self.path: - data = data.copy() # we're going to modify - # Ensure there's a "reply" key in data, even if there wasn't before - data["reply"] = data.get("reply", llsd.LLSD("success")) - response = llsd.format_xml(data) - debug("success: %s", response) - self.send_response(200) - if "/reflect/" in self.path: - self.reflect_headers() - self.send_header("Content-type", "application/llsd+xml") - self.send_header("Content-Length", str(len(response))) - self.send_header("X-LL-Special", "Mememememe"); - self.end_headers() - if withdata: - self.wfile.write(response) - else: # fail requested + if "fail" in self.path: status = data.get("status", 500) # self.responses maps an int status to a (short, long) pair of # strings. We want the longer string. That's why we pass a string @@ -138,6 +159,57 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler): if "/reflect/" in self.path: self.reflect_headers() self.end_headers() + elif "/bug2295/" in self.path: + # Test for https://jira.secondlife.com/browse/BUG-2295 + # + # Client can receive a header indicating data should + # appear in the body without actually getting the body. + # Library needs to defend against this case. + # + body = None + if "/bug2295/0/" in self.path: + self.send_response(206) + self.send_header("Content-Range", "bytes 0-75/2983") + elif "/bug2295/1/" in self.path: + self.send_response(206) + self.send_header("Content-Range", "bytes 0-75/*") + elif "/bug2295/2/" in self.path: + self.send_response(206) + self.send_header("Content-Range", "bytes 0-75/2983") + self.send_header("Content-Length", "0") + elif "/bug2295/00000012/0/" in self.path: + self.send_response(206) + self.send_header("Content-Range", "bytes 0-75/2983") + self.send_header("Content-Length", "76") + elif "/bug2295/inv_cont_range/0/" in self.path: + self.send_response(206) + self.send_header("Content-Range", "bytes 0-75/2983") + body = "Some text, but not enough." + else: + # Unknown request + self.send_response(400) + if "/reflect/" in self.path: + self.reflect_headers() + self.send_header("Content-type", "text/plain") + self.end_headers() + if body: + self.wfile.write(body) + else: + # Normal response path + data = data.copy() # we're going to modify + # Ensure there's a "reply" key in data, even if there wasn't before + data["reply"] = data.get("reply", llsd.LLSD("success")) + response = llsd.format_xml(data) + debug("success: %s", response) + self.send_response(200) + if "/reflect/" in self.path: + self.reflect_headers() + self.send_header("Content-type", "application/llsd+xml") + self.send_header("Content-Length", str(len(response))) + self.send_header("X-LL-Special", "Mememememe"); + self.end_headers() + if withdata: + self.wfile.write(response) def reflect_headers(self): for name in self.headers.keys(): @@ -162,6 +234,17 @@ class Server(ThreadingMixIn, HTTPServer): # operation of freeport() absolutely depends on it being off. allow_reuse_address = False + # Override of BaseServer.handle_error(). Not too interested + # in errors and the default handler emits a scary traceback + # to stderr which annoys some. Disable this override to get + # default behavior which *shouldn't* cause the program to return + # a failure status. + def handle_error(self, request, client_address): + print '-'*40 + print 'Ignoring exception during processing of request from', + print client_address + print '-'*40 + if __name__ == "__main__": do_valgrind = False path_search = False @@ -188,3 +271,4 @@ if __name__ == "__main__": args = ["valgrind", "--log-file=./valgrind.log"] + args path_search = True sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), use_path=path_search, *args)) + diff --git a/indra/llcorehttp/tests/test_refcounted.hpp b/indra/llcorehttp/tests/test_refcounted.hpp index cb4b50287a..cb4b50287a 100644..100755 --- a/indra/llcorehttp/tests/test_refcounted.hpp +++ b/indra/llcorehttp/tests/test_refcounted.hpp diff --git a/indra/llcorehttp/tests/testrunner.py b/indra/llcorehttp/tests/testrunner.py index 9a2de71142..9a2de71142 100644..100755 --- a/indra/llcorehttp/tests/testrunner.py +++ b/indra/llcorehttp/tests/testrunner.py |