Skip to content

Commit cd9c2c2

Browse files
author
hideki
committed
Fixed #1180 - Router: PUT /{db}/{doc} If-Match header is not supported
1 parent 7e81bdc commit cd9c2c2

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/java/com/couchbase/lite/router/Router.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ private static String getAccept(URLConnection connection) {
375375
return accept;
376376
}
377377

378+
private static String getIfMatch(URLConnection connection) {
379+
String ifMatch = connection.getRequestProperty("If-Match");
380+
if (ifMatch == null)
381+
// From Android: http://developer.android.com/reference/java/net/URLConnection.html
382+
ifMatch = connection.getRequestProperty("if-match");
383+
return ifMatch;
384+
}
385+
378386
public void start() {
379387
// Refer to: http://wiki.apache.org/couchdb/Complete_HTTP_API_Reference
380388

@@ -2088,7 +2096,13 @@ private Status update(Database _db, String docID, Body body, boolean deleting) {
20882096
if (docID != null && docID.isEmpty() == false) {
20892097
// On PUT/DELETE, get revision ID from either ?rev= query or doc body:
20902098
String revParam = getQuery("rev");
2091-
2099+
String ifMatch = getIfMatch(connection);
2100+
if (ifMatch != null) {
2101+
if(revParam == null)
2102+
revParam = ifMatch;
2103+
else if(!ifMatch.equals(revParam))
2104+
return new Status(Status.BAD_REQUEST);
2105+
}
20922106
if (revParam != null && body != null) {
20932107
String revProp = (String) body.getProperties().get("_rev");
20942108
if (revProp == null) {

0 commit comments

Comments
 (0)