Permalink
Browse files

COUCHDB-1337 - Use attachments md5 as ETag if available

  • Loading branch information...
1 parent c4c8d94 commit 6d912c9fe361203ee3245a4dc2ee2c2fdd9ce939 @rnewson rnewson committed Nov 7, 2011
Showing with 12 additions and 3 deletions.
  1. +3 −0 CHANGES
  2. +3 −0 NEWS
  3. +1 −1 share/www/script/test/attachment_names.js
  4. +1 −1 share/www/script/test/attachments.js
  5. +4 −1 src/couchdb/couch_httpd_db.erl
View
@@ -76,6 +76,9 @@ Version 1.1.2
This version has not been released yet.
+* ETag of attachment changes only when the attachment changes, not
+ the document.
+
Version 1.1.1
-------------
View
3 NEWS
@@ -46,6 +46,9 @@ Version 1.1.2
This version has not been released yet.
+* ETag of attachment changes only when the attachment changes, not
+ the document.
+
Version 1.1.1
-------------
@@ -32,7 +32,7 @@ couchTests.attachment_names = function(debug) {
var xhr = CouchDB.request("GET", "/test_suite_db/good_doc/Колян.txt");
T(xhr.responseText == "This is a base64 encoded text");
T(xhr.getResponseHeader("Content-Type") == "text/plain");
- T(xhr.getResponseHeader("Etag") == '"' + save_response.rev + '"');
+ TEquals("\"qUUYqS41RhwF0TrCsTAxFg==\"", xhr.getResponseHeader("Etag"));
var binAttDoc = {
_id: "bin_doc",
@@ -32,7 +32,7 @@ couchTests.attachments= function(debug) {
var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt");
T(xhr.responseText == "This is a base64 encoded text");
T(xhr.getResponseHeader("Content-Type") == "text/plain");
- T(xhr.getResponseHeader("Etag") == '"' + save_response.rev + '"');
+ TEquals("\"qUUYqS41RhwF0TrCsTAxFg==\"", xhr.getResponseHeader("Etag"));
// empty attachment
var binAttDoc2 = {
@@ -957,7 +957,10 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
[] ->
throw({not_found, "Document is missing attachment"});
[#att{type=Type, encoding=Enc, disk_len=DiskLen, att_len=AttLen}=Att] ->
- Etag = couch_httpd:doc_etag(Doc),
+ Etag = case Att#att.md5 of
+ <<>> -> couch_httpd:doc_etag(Doc);
+ Md5 -> "\"" ++ ?b2l(base64:encode(Md5)) ++ "\""
+ end,
ReqAcceptsAttEnc = lists:member(
atom_to_list(Enc),
couch_httpd:accepted_encodings(Req)

0 comments on commit 6d912c9

Please sign in to comment.