diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-04-12 09:16:25 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-04-12 09:16:25 -0400 |
commit | a8cdcfc9a893b7debf7c006022b57c389b50bf0d (patch) | |
tree | 95930cdb0ab0249b6666c57dc94857fa4dfaf403 /indra | |
parent | e17920defbf1d39ecd9e88500ba268c59bb84008 (diff) |
SH-4061 WIP - moved retry policy to newview so it can work with either llmessage or CoreHttp libraries. Updated tests.
Diffstat (limited to 'indra')
-rwxr-xr-x | indra/llmessage/CMakeLists.txt | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | indra/newview/CMakeLists.txt | 5 | ||||
-rwxr-xr-x | indra/newview/llhttpretrypolicy.cpp (renamed from indra/llmessage/llhttpretrypolicy.cpp) | 39 | ||||
-rwxr-xr-x | indra/newview/llhttpretrypolicy.h (renamed from indra/llmessage/llhttpretrypolicy.h) | 7 | ||||
-rwxr-xr-x | indra/newview/lltexturefetch.h | 2 | ||||
-rwxr-xr-x | indra/newview/tests/llhttpretrypolicy_test.cpp (renamed from indra/llmessage/tests/llhttpretrypolicy_test.cpp) | 59 |
6 files changed, 104 insertions, 10 deletions
diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt index 6df724f960..6fa2669be6 100755 --- a/indra/llmessage/CMakeLists.txt +++ b/indra/llmessage/CMakeLists.txt @@ -67,7 +67,6 @@ set(llmessage_SOURCE_FILES llpartdata.cpp llproxy.cpp llpumpio.cpp - llhttpretrypolicy.cpp llsdappservices.cpp llsdhttpserver.cpp llsdmessage.cpp @@ -267,6 +266,5 @@ if (LL_TESTS) LL_ADD_INTEGRATION_TEST(llhttpclientadapter "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llpartdata "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llxfer_file "" "${test_libs}") - LL_ADD_INTEGRATION_TEST(llhttpretrypolicy "" "${test_libs}") endif (LL_TESTS) diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 05736f6360..27dbe15005 100644..100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -299,6 +299,7 @@ set(viewer_SOURCE_FILES llgroupmgr.cpp llhints.cpp llhomelocationresponder.cpp + llhttpretrypolicy.cpp llhudeffect.cpp llhudeffectbeam.cpp llhudeffectlookat.cpp @@ -877,6 +878,7 @@ set(viewer_HEADER_FILES llgrouplist.h llgroupmgr.h llhints.h + llhttpretrypolicy.h llhomelocationresponder.h llhudeffect.h llhudeffectbeam.h @@ -2152,6 +2154,7 @@ if (LL_TESTS) set(test_libs ${LLMESSAGE_LIBRARIES} + ${LLCOREHTTP_LIBRARIES} ${WINDOWS_LIBRARIES} ${LLVFS_LIBRARIES} ${LLMATH_LIBRARIES} @@ -2197,6 +2200,8 @@ if (LL_TESTS) "${test_libs}" ) + LL_ADD_INTEGRATION_TEST(llhttpretrypolicy "llhttpretrypolicy.cpp" "${test_libs}") + #ADD_VIEWER_BUILD_TEST(llmemoryview viewer) #ADD_VIEWER_BUILD_TEST(llagentaccess viewer) #ADD_VIEWER_BUILD_TEST(lltextureinfo viewer) diff --git a/indra/llmessage/llhttpretrypolicy.cpp b/indra/newview/llhttpretrypolicy.cpp index 7e4dfc7250..5c6dabbe99 100755 --- a/indra/llmessage/llhttpretrypolicy.cpp +++ b/indra/newview/llhttpretrypolicy.cpp @@ -24,21 +24,56 @@ * $/LicenseInfo$ */ -#include "linden_common.h" +#include "llviewerprecompiledheaders.h" + #include "llhttpretrypolicy.h" -bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, retry_header_time) +bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, F32& retry_header_time) { return (headers.has(HTTP_IN_HEADER_RETRY_AFTER) && getSecondsUntilRetryAfter(headers[HTTP_IN_HEADER_RETRY_AFTER].asStringRef(), retry_header_time)); } +bool LLAdaptiveRetryPolicy::getRetryAfter(const LLCore::HttpHeaders *headers, F32& retry_header_time) +{ + // Look for matching header. Hopefully it's correct enough to let + // us extract the field we are looking for. Does not purport to be + // in any way a viable general HTTP header parser. + if (headers) + { + for (std::vector<std::string>::const_iterator it = headers->mHeaders.begin(); + it != headers->mHeaders.end(); + ++it) + { + const std::string& str = *it; + const std::string match = HTTP_IN_HEADER_RETRY_AFTER + ":"; + size_t pos = str.find(match); + if ((pos != std::string::npos) && + (pos+match.length() <= str.length())) + { + retry_header_time = strtod(str.substr(pos+match.length()).c_str(), NULL); + return true; + } + } + } + return false; +} + void LLAdaptiveRetryPolicy::onFailure(S32 status, const LLSD& headers) { F32 retry_header_time; bool has_retry_header_time = getRetryAfter(headers,retry_header_time); onFailureCommon(status, has_retry_header_time, retry_header_time); } + +// TODO: replace this parsing junk once CoreHttp has its own header parsing capabilities. +void LLAdaptiveRetryPolicy::onFailure(const LLCore::HttpResponse *response) +{ + F32 retry_header_time; + const LLCore::HttpHeaders *headers = response->getHeaders(); + bool has_retry_header_time = getRetryAfter(headers,retry_header_time); + onFailureCommon(response->getStatus().mType, has_retry_header_time, retry_header_time); +} void LLAdaptiveRetryPolicy::onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time) { diff --git a/indra/llmessage/llhttpretrypolicy.h b/indra/newview/llhttpretrypolicy.h index cf27bb3048..ca37e5f73c 100755 --- a/indra/llmessage/llhttpretrypolicy.h +++ b/indra/newview/llhttpretrypolicy.h @@ -46,7 +46,7 @@ public: // Call once after an HTTP failure to update state. virtual void onFailure(S32 status, const LLSD& headers) = 0; - virtual void onFailure(const HttpResponse *response, const HttpHeaders *headers) = 0; + virtual void onFailure(const LLCore::HttpResponse *response) = 0; virtual bool shouldRetry(F32& seconds_to_wait) const = 0; }; @@ -70,12 +70,13 @@ public: // virtual void onFailure(S32 status, const LLSD& headers); // virtual - void onFailure(const HttpResponse *response, const HttpHeaders *headers); + void onFailure(const LLCore::HttpResponse *response); // virtual bool shouldRetry(F32& seconds_to_wait) const; protected: - bool getRetryAfter(const LLSD& headers, retry_header_time) + bool getRetryAfter(const LLSD& headers, F32& retry_header_time); + bool getRetryAfter(const LLCore::HttpHeaders *headers, F32& retry_header_time); void onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time); private: diff --git a/indra/newview/lltexturefetch.h b/indra/newview/lltexturefetch.h index c6bd342a7b..12226d51c8 100755 --- a/indra/newview/lltexturefetch.h +++ b/indra/newview/lltexturefetch.h @@ -397,7 +397,7 @@ private: e_tex_source mOriginFetchSource; // Retry logic - LLAdaptiveRetryPolicy mFetchRetryPolicy; + //LLAdaptiveRetryPolicy mFetchRetryPolicy; public: //debug use diff --git a/indra/llmessage/tests/llhttpretrypolicy_test.cpp b/indra/newview/tests/llhttpretrypolicy_test.cpp index ebf626d9a8..39bd15d62f 100755 --- a/indra/llmessage/tests/llhttpretrypolicy_test.cpp +++ b/indra/newview/tests/llhttpretrypolicy_test.cpp @@ -24,8 +24,8 @@ * $/LicenseInfo$ */ -#include "linden_common.h" -#include "llhttpretrypolicy.h" +#include "../llviewerprecompiledheaders.h" +#include "../llhttpretrypolicy.h" #include "lltut.h" namespace tut @@ -216,5 +216,60 @@ void RetryPolicyTestObject::test<6>() ensure_approximately_equals("parse 3", seconds_to_wait, 0.0F, 6); } +// Test retry-after field in both llmessage and CoreHttp headers. +template<> template<> +void RetryPolicyTestObject::test<7>() +{ + LLSD sd_headers; + time_t nowseconds; + time(&nowseconds); + sd_headers[HTTP_IN_HEADER_RETRY_AFTER] = LLDate((F64)nowseconds).asRFC1123(); + LLAdaptiveRetryPolicy policy(17.0,644.0,3.0,10); + F32 seconds_to_wait; + bool should_retry; + + // no retry header, use default. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 1", should_retry); + ensure_approximately_equals("header 1", seconds_to_wait, 17.0F, 6); + + // retry header should override, give delay of 0 + policy.onFailure(503,sd_headers); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 2", should_retry); + ensure_approximately_equals("header 2", seconds_to_wait, 0.0F, 6); + + // retry header in LLCore::HttpHeaders + { + LLCore::HttpResponse *response = new LLCore::HttpResponse(); + LLCore::HttpHeaders *headers = new LLCore::HttpHeaders(); + response->setStatus(503); + response->setHeaders(headers); + headers->mHeaders.push_back("retry-after: 600"); + policy.onFailure(response); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 3",should_retry); + ensure_approximately_equals("header 3", seconds_to_wait, 600.0F, 6); + response->release(); + } + + // retry header in LLCore::HttpHeaders + { + LLCore::HttpResponse *response = new LLCore::HttpResponse(); + LLCore::HttpHeaders *headers = new LLCore::HttpHeaders(); + response->setStatus(503); + response->setHeaders(headers); + LLSD sd_headers; + time(&nowseconds); + headers->mHeaders.push_back("retry-after: " + LLDate((F64)nowseconds).asRFC1123()); + policy.onFailure(response); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 3",should_retry); + ensure_approximately_equals("header 3", seconds_to_wait, 0.0F, 6); + response->release(); + } +} + } |