diff options
author | Rider Linden <rider@lindenlab.com> | 2015-09-15 17:01:26 -0700 |
---|---|---|
committer | Rider Linden <rider@lindenlab.com> | 2015-09-15 17:01:26 -0700 |
commit | 907efc9cc9bcf4a935ed0e1bd17b19da2bb99dce (patch) | |
tree | 8453041f5ba3e07fbe0e7d2a632ee1fbf08698e7 /indra/newview/llhttpretrypolicy.cpp | |
parent | 5f7985f6a79a21256162785cd9f0b97baac0504a (diff) |
MAINT-5507: Remove llcurl, move constant values and untilities to llcorehttp lib
Diffstat (limited to 'indra/newview/llhttpretrypolicy.cpp')
-rwxr-xr-x | indra/newview/llhttpretrypolicy.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/indra/newview/llhttpretrypolicy.cpp b/indra/newview/llhttpretrypolicy.cpp index e2e151eb63..6a2daeeb90 100755 --- a/indra/newview/llhttpretrypolicy.cpp +++ b/indra/newview/llhttpretrypolicy.cpp @@ -25,9 +25,23 @@ */ #include "llviewerprecompiledheaders.h" - #include "llhttpretrypolicy.h" +namespace +{ + // Moved from httpconstants.h... only used in this file. + bool isHttpServerErrorStatus(S32 status) + { + // Status 499 is sometimes used for re-interpreted status 2xx errors. + // Allow retry of these, since we don't have enough information in this + // context to know if this will always fail. + if (HTTP_INTERNAL_ERROR == status) return true; + + // Check for status 5xx. + return((500 <= status) && (status < 600)); + } +} + LLAdaptiveRetryPolicy::LLAdaptiveRetryPolicy(F32 min_delay, F32 max_delay, F32 backoff_factor, U32 max_retries, bool retry_on_4xx): mMinDelay(min_delay), mMaxDelay(max_delay), @@ -140,3 +154,34 @@ bool LLAdaptiveRetryPolicy::shouldRetry(F32& seconds_to_wait) const seconds_to_wait = mShouldRetry ? (F32) mRetryTimer.getRemainingTimeF32() : F32_MAX; return mShouldRetry; } + +// Moved from httpconstants. Only used by this file. +// Parses 'Retry-After' header contents and returns seconds until retry should occur. +/*static*/ +bool LLAdaptiveRetryPolicy::getSecondsUntilRetryAfter(const std::string& retry_after, F32& seconds_to_wait) +{ + // *TODO: This needs testing! Not in use yet. + // Examples of Retry-After headers: + // Retry-After: Fri, 31 Dec 1999 23:59:59 GMT + // Retry-After: 120 + + // Check for number of seconds version, first: + char* end = 0; + // Parse as double + double seconds = std::strtod(retry_after.c_str(), &end); + if (end != 0 && *end == 0) + { + // Successful parse + seconds_to_wait = (F32)seconds; + return true; + } + + // Parse rfc1123 date. + time_t date = curl_getdate(retry_after.c_str(), NULL); + if (-1 == date) return false; + + seconds_to_wait = (F64)date - LLTimer::getTotalSeconds(); + + return true; +} + |