diff options
author | James Cook <james@lindenlab.com> | 2010-05-07 10:41:02 -0700 |
---|---|---|
committer | James Cook <james@lindenlab.com> | 2010-05-07 10:41:02 -0700 |
commit | fa03333d5893f16318a33e9edfae782ca0125768 (patch) | |
tree | 325bc292aed2e7872dfc16a0d6490bdcf9b22b91 /indra/llmessage | |
parent | 17e2739a363447f5e12c9d84ab319f51e99e942a (diff) |
DEV-49633 Prefer Retry-After for error handling backoff
Also, we can't parse Expires dates, so use Cache-Control max-age.
Reviewed with Huseby.
Diffstat (limited to 'indra/llmessage')
-rw-r--r-- | indra/llmessage/llavatarnamecache.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index 701f3931d0..fdbc28656e 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -122,6 +122,8 @@ namespace LLAvatarNameCache // Erase expired names from cache void eraseExpired(); + + bool expirationFromCacheControl(LLSD headers, F64 *expires); } /* Sample response: @@ -244,34 +246,29 @@ public: // error type and headers. Return value is seconds-since-epoch. F64 errorRetryTimestamp(S32 status) { - LLSD expires = mHeaders["expires"]; - if (expires.isDefined()) - { - LLDate expires_date = expires.asDate(); - return expires_date.secondsSinceEpoch(); - } + F64 now = LLFrameTimer::getTotalSeconds(); + // Retry-After takes priority LLSD retry_after = mHeaders["retry-after"]; if (retry_after.isDefined()) { - // does the header use the delta-seconds type? + // We only support the delta-seconds type S32 delta_seconds = retry_after.asInteger(); if (delta_seconds > 0) { // ...valid delta-seconds - F64 now = LLFrameTimer::getTotalSeconds(); return now + F64(delta_seconds); } - else - { - // ...it's a date - LLDate expires_date = retry_after.asDate(); - return expires_date.secondsSinceEpoch(); - } + } + + // If no Retry-After, look for Cache-Control max-age + F64 expires = 0.0; + if (LLAvatarNameCache::expirationFromCacheControl(mHeaders, &expires)) + { + return expires; } // No information in header, make a guess - F64 now = LLFrameTimer::getTotalSeconds(); if (status == 503) { // ...service unavailable, retry soon @@ -683,11 +680,22 @@ void LLAvatarNameCache::insert(const LLUUID& agent_id, const LLAvatarName& av_na F64 LLAvatarNameCache::nameExpirationFromHeaders(LLSD headers) { - // With no expiration info, default to a day - const F64 DEFAULT_EXPIRES = 24.0 * 60.0 * 60.0; - F64 now = LLFrameTimer::getTotalSeconds(); - F64 expires = now + DEFAULT_EXPIRES; + F64 expires = 0.0; + if (expirationFromCacheControl(headers, &expires)) + { + return expires; + } + else + { + // With no expiration info, default to a day + const F64 DEFAULT_EXPIRES = 24.0 * 60.0 * 60.0; + F64 now = LLFrameTimer::getTotalSeconds(); + return now + DEFAULT_EXPIRES; + } +} +bool LLAvatarNameCache::expirationFromCacheControl(LLSD headers, F64 *expires) +{ // Allow the header to override the default LLSD cache_control_header = headers["cache-control"]; if (cache_control_header.isDefined()) @@ -696,10 +704,12 @@ F64 LLAvatarNameCache::nameExpirationFromHeaders(LLSD headers) std::string cache_control = cache_control_header.asString(); if (max_age_from_cache_control(cache_control, &max_age)) { - expires = now + (F64)max_age; + F64 now = LLFrameTimer::getTotalSeconds(); + *expires = now + (F64)max_age; + return true; } } - return expires; + return false; } static const std::string MAX_AGE("max-age"); |