You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2016/04/07 16:08:06 UTC

couch commit: updated refs/heads/local-docs-2978 to 50722ae

Repository: couchdb-couch
Updated Branches:
  refs/heads/local-docs-2978 [created] 50722ae6f


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


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/50722ae6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/50722ae6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/50722ae6

Branch: refs/heads/local-docs-2978
Commit: 50722ae6f3263a06c07550c29392966088c0336c
Parents: c256ef5
Author: Garren Smith <ga...@gmail.com>
Authored: Thu Apr 7 16:06:31 2016 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Thu Apr 7 16:06:31 2016 +0200

----------------------------------------------------------------------
 src/couch_httpd.erl | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/50722ae6/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 7370594..c4f5a9c 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -21,7 +21,7 @@
 -export([make_fun_spec_strs/1]).
 -export([make_arity_1_fun/1, make_arity_2_fun/1, make_arity_3_fun/1]).
 -export([parse_form/1,json_body/1,json_body_obj/1,body/1]).
--export([doc_etag/1, make_etag/1, etag_match/2, etag_respond/3, etag_maybe/2]).
+-export([doc_etag/1, doc_etag/3, make_etag/1, etag_match/2, etag_respond/3, etag_maybe/2]).
 -export([primary_header_value/2,partition/1,serve_file/3,serve_file/4, server_header/0]).
 -export([start_chunked_response/3,send_chunk/2,log_request/2]).
 -export([start_response_length/4, start_response/3, send/2]).
@@ -594,8 +594,17 @@ maybe_decompress(Httpd, Body) ->
         throw({bad_ctype, [Else, " is not a supported content encoding."]})
     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|_]}}) ->
+    doc_etag(Id, Body, {Start, DiskRev}).
+
+doc_etag(<<"_local/", _/binary>>, Body, {Start, DiskRev}) ->
+    make_etag({Start, DiskRev, Body});
+doc_etag(_Id, _Body, {Start, DiskRev}) ->
+    rev_etag({Start, DiskRev}).
+
+rev_etag({Start, DiskRev}) ->
+    Rev = couch_doc:rev_to_str({Start, DiskRev}),
+     <<$", Rev/binary, $">>.
 
 make_etag(Term) ->
     <<SigInt:128/integer>> = couch_crypto:hash(md5, term_to_binary(Term)),