From 51e42914f3666ee6e0bc16a4c78f60b117265c24 Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Mon, 23 Jul 2012 16:00:21 +0800 Subject: [PATCH] refreshing the token if HTTP 401 is returned (#83) --- README | 11 +++++++++-- libgrive/src/protocol/AuthAgent.cc | 12 ++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README b/README index 5130b11..4b42df3 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Grive 0.2.0 +Grive 0.3.0 9 June 2012 http://www.lbreda.com/grive/ @@ -14,7 +14,6 @@ There are a few things that Grive does not do at the moment: - wait for changes in file system to occur and upload. A sync is only performed when you run Grive. - symbolic links support - support for Google documents -- support for files >2GB Of course these will be added in the future, possibly the next release. @@ -48,3 +47,11 @@ current directory. It will also start downloading files from your Google Drive t your current directory. Enjoy! + +Version History: + +Grive v0.3: Bug fix release +Fixed bugs: + #93: missing reference count increment in one of the Json constructors + #82: retry for HTTP error 500 & 503 + #77: Fixed a bug where grive crashed on the first run. diff --git a/libgrive/src/protocol/AuthAgent.cc b/libgrive/src/protocol/AuthAgent.cc index b54f232..15732a4 100644 --- a/libgrive/src/protocol/AuthAgent.cc +++ b/libgrive/src/protocol/AuthAgent.cc @@ -125,6 +125,7 @@ std::string AuthAgent::Unescape( const std::string& str ) bool AuthAgent::CheckRetry( long response ) { + // HTTP 500 and 503 should be temperory. just wait a bit and retry if ( response == 500 || response == 503 ) { Log( "resquest failed due to temperory error: %1%. retrying in 5 seconds", @@ -133,6 +134,17 @@ bool AuthAgent::CheckRetry( long response ) os::Sleep( 5 ) ; return true ; } + + // HTTP 401 Unauthorized. the auth token has been expired. refresh it + else if ( response == 401 ) + { + Log( "resquest failed due to auth token expired: %1%. refreshing token", + response, log::warning ) ; + + m_auth.Refresh() ; + return true ; + } + else return false ; }