From 3368134b760178287f1101d403a1f0ed5caf5e23 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Sun, 25 May 2008 21:48:00 +0000 Subject: Enable Etag processing for document GET requests that include the '?rev' query string parameter. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@660046 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index fcbe66a0..239fd697 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -474,31 +474,30 @@ handle_doc_request(Req, 'GET', _DbName, Db, DocId) -> case Revs of [] -> case Rev of - "" -> - % open most recent rev + "" -> % open most recent rev case couch_db:open_doc(Db, DocId, Options) of - {ok, #doc{revs=[DocRev|_]}=Doc} -> - Etag = none_match(Req, DocRev), - JsonDoc = couch_doc:to_json_obj(Doc, Options), - AdditionalHeaders = - case Doc#doc.meta of - [] -> [{"Etag", Etag}]; % output etag when we have no meta - _ -> [] - end, - send_json(Req, 200, AdditionalHeaders, JsonDoc); - Error -> - throw(Error) + {ok, #doc{revs=[DocRev|_]}=Doc} -> + true; + Error -> + Doc = DocRev = undefined, + throw(Error) end; - _ -> - % open a specific rev (deletions come back as stubs) + _ -> % open a specific rev (deletions come back as stubs) case couch_db:open_doc_revs(Db, DocId, [Rev], Options) of - {ok, [{ok, Doc}]} -> - send_json(Req, 200, [], - couch_doc:to_json_obj(Doc, Options)); - {ok, [Else]} -> - throw(Else) + {ok, [{ok, Doc}]} -> + DocRev = Rev; + {ok, [Else]} -> + Doc = DocRev = undefined, + throw(Else) end - end; + end, + Etag = none_match(Req, DocRev), + AdditionalHeaders = case Doc#doc.meta of + [] -> [{"Etag", Etag}]; % output etag when we have no meta + _ -> [] + end, + JsonDoc = couch_doc:to_json_obj(Doc, Options), + send_json(Req, 200, AdditionalHeaders, JsonDoc); _ -> {ok, Results} = couch_db:open_doc_revs(Db, DocId, Revs, Options), Resp = start_json_response(Req, 200), -- cgit v1.2.3