Permalink
Browse files

Create md5 etag for _local docs

This makes a unique ETAG for _local docs, so that they are cached
correctly, and fetched again when the document changes.

fixes COUCHDB-2978
  • Loading branch information...
garrensmith committed Apr 7, 2016
1 parent cefabd0 commit 1ca86421bafd17cc5b954d9075e3a053ea951f6a
Showing with 5 additions and 5 deletions.
  1. +2 −2 src/chttpd.erl
  2. +3 −3 src/chttpd_db.erl
@@ -621,8 +621,8 @@ json_body_obj(Httpd) ->
end.


doc_etag(#doc{revs={Start, [DiskRev|_]}}) ->
"\"" ++ ?b2l(couch_doc:rev_to_str({Start, DiskRev})) ++ "\"".
doc_etag(#doc{id=Id, body=Body, revs={Start, [DiskRev|_]}}) ->
couch_httpd:doc_etag(Id, Body, {Start, DiskRev}).

make_etag(Term) ->
<<SigInt:128/integer>> = couch_crypto:hash(md5, term_to_binary(Term)),
@@ -950,7 +950,7 @@ http_code_from_status(Status) ->
200
end.

update_doc(Db, DocId, #doc{deleted=Deleted}=Doc, Options) ->
update_doc(Db, DocId, #doc{deleted=Deleted, body=DocBody}=Doc, Options) ->
{_, Ref} = spawn_monitor(fun() ->
try fabric:update_doc(Db, Doc, Options) of
Resp ->
@@ -981,8 +981,7 @@ update_doc(Db, DocId, #doc{deleted=Deleted}=Doc, Options) ->
{accepted, NewRev} ->
Accepted = true
end,
NewRevStr = couch_doc:rev_to_str(NewRev),
Etag = <<"\"", NewRevStr/binary, "\"">>,
Etag = couch_httpd:doc_etag(DocId, DocBody, NewRev),
Status = case {Accepted, Deleted} of
{true, _} ->
accepted;
@@ -991,6 +990,7 @@ update_doc(Db, DocId, #doc{deleted=Deleted}=Doc, Options) ->
{false, false} ->
created
end,
NewRevStr = couch_doc:rev_to_str(NewRev),
Body = {[{ok, true}, {id, DocId}, {rev, NewRevStr}]},
{Status, {etag, Etag}, Body}.

0 comments on commit 1ca8642

Please sign in to comment.