Skip to content

Commit 266e30c

Browse files
authored
Merge pull request #1405 from couchbase/feature/issue_978
Fixed https://github.com/couchbase/couchbase-lite-android/issues/978
2 parents b34278d + 7c62ab1 commit 266e30c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/com/couchbase/lite/replicator/ChangeTracker.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)