You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2015/06/02 21:31:25 UTC

[35/41] chttpd commit: updated refs/heads/2080-port-cors to e2c2bd7

Use attachment checksum as Etag if possible

Fixes COUCHDB-2668

Originally fixed in COUCHDB-1337


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

Branch: refs/heads/2080-port-cors
Commit: ab80f3131e244af967e2d162925ee45008d54a50
Parents: 2f53652
Author: Robert Newson <rn...@apache.org>
Authored: Sun Apr 19 10:41:14 2015 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sun Apr 19 10:43:30 2015 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/ab80f313/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index ab0b8b0..27fa745 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1011,10 +1011,13 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
     [] ->
         throw({not_found, "Document is missing attachment"});
     [Att] ->
-        [Type, Enc, DiskLen, AttLen] = couch_att:fetch([type, encoding, disk_len, att_len], Att),
+        [Type, Enc, DiskLen, AttLen, Md5] = couch_att:fetch([type, encoding, disk_len, att_len, md5], Att),
         Refs = monitor_attachments(Att),
         try
-        Etag = chttpd:doc_etag(Doc),
+        Etag = case Md5 of
+            <<>> -> chttpd:doc_etag(Doc);
+            _ -> "\"" ++ ?b2l(base64:encode(Md5)) ++ "\""
+        end,
         ReqAcceptsAttEnc = lists:member(
            atom_to_list(Enc),
            couch_httpd:accepted_encodings(Req)