File tree Expand file tree Collapse file tree
src/main/java/com/couchbase/lite/replicator Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -266,12 +266,23 @@ private boolean isResponseFailed(Response response) {
266266 private boolean retryIfFailedPost (Response response ) {
267267 if (!usePOST )
268268 return false ;
269- if (response .code () != Status .METHOD_NOT_ALLOWED )
269+ if (response .code () != Status .METHOD_NOT_ALLOWED && ! isCloudantAuthError ( response ) )
270270 return false ;
271271 usePOST = false ;
272272 return true ;
273273 }
274274
275+ // Cloudant returns 401 or 403 if we send it a POST to _changes for a write-protected database.
276+ // (See issues iOS #1020, #1267, Android #978)
277+ private boolean isCloudantAuthError (Response response ) {
278+ String server = response .header ("Server" );
279+ if (server == null || server .indexOf ("CouchDB/1.0.2" ) == -1 )// (Accurate as of 5/2016)
280+ return false ;
281+ // Note: 401 (UNAUTHORIZED) might not be caused by Cloudant
282+ // Before adding fix for 401, we need a test environment.
283+ return response .code () == Status .FORBIDDEN ;
284+ }
285+
275286 protected void runLoop () {
276287 paused = false ;
277288
You can’t perform that action at this time.
0 commit comments