private Status update(Database _db, String docID, Body body, boolean deleting) {
        Status status = new Status();

        if (docID != null && docID.isEmpty() == false) {
            // On PUT/DELETE, get revision ID from either ?rev= query or doc body:
            String revParam = getQuery("rev");
            String ifMatch = getRequestHeaderValue("If-Match");
            if (ifMatch != null) {
                if (revParam == null)
                    revParam = ifMatch;
                else if (!ifMatch.equals(revParam))
                    return new Status(Status.BAD_REQUEST);
            }
            if (revParam != null && body != null) {
                String revProp = (String) body.getProperties().get("_rev");
                if (revProp == null) {
                    // No _rev property in body, so use ?rev= query param instead:
                    body.getProperties().put("_rev", revParam);
                    //body = new Body(bodyDict);
                } else if (!revParam.equals(revProp)) {
                    throw new IllegalArgumentException("Mismatch between _rev and rev");
                }
            }
        }

        RevisionInternal rev = update(_db, docID, body, deleting, false, status);
        if (status.isSuccessful()) {
            cacheWithEtag(rev.getRevID());  // set ETag
            if (!deleting) {
                URL url = connection.getURL();
                String urlString = url.toExternalForm();
                if (docID != null) {
                    urlString += '/' + rev.getDocID();
                    try {
                        url = new URL(urlString);
                    } catch (MalformedURLException e) {
                        Log.w("Malformed URL", e);
                    }
                }
                setResponseLocation(url);
            }
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("ok", true);
            result.put("id", rev.getDocID());
            result.put("rev", rev.getRevID());
            connection.setResponseBody(new Body(result));
        }
        return status;
    }
private Status update ( Database _db , String docID , Body body , boolean deleting ) { Status status = new Status ( ) ; if ( docID != null && docID . isEmpty ( ) == false ) { String revParam = getQuery ( "rev" ) ; String ifMatch = getRequestHeaderValue ( "If-Match" ) ; if ( ifMatch != null ) { if ( revParam == null ) revParam = ifMatch ; else if ( ! ifMatch . equals ( revParam ) ) return new Status ( Status . BAD_REQUEST ) ; } if ( revParam != null && body != null ) { String revProp = ( String ) body . getProperties ( ) . get ( "_rev" ) ; if ( revProp == null ) { body . getProperties ( ) . put ( "_rev" , revParam ) ; } else if ( ! revParam . equals ( revProp ) ) { throw new IllegalArgumentException ( "Mismatch between _rev and rev" ) ; } } } RevisionInternal rev = update ( _db , docID , body , deleting , false , status ) ; if ( status . isSuccessful ( ) ) { cacheWithEtag ( rev . getRevID ( ) ) ; if ( ! deleting ) { URL url = connection . getURL ( ) ; String urlString = url . toExternalForm ( ) ; if ( docID != null ) { urlString += '/' + rev . getDocID ( ) ; try { url = new URL ( urlString ) ; } catch ( MalformedURLException e ) { Log . w ( "Malformed URL" , e ) ; } } setResponseLocation ( url ) ; } Map < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "ok" , true ) ; result . put ( "id" , rev . getDocID ( ) ) ; result . put ( "rev" , rev . getRevID ( ) ) ; connection . setResponseBody ( new Body ( result ) ) ; } return status ; }
in CBL_Router+Handlers.m
- (CBLStatus) update: (CBLDatabase*)db
docID: (NSString*)docID
body: (CBL_Body*)body
deleting: (BOOL)deleting
error: (NSError**)outError