diff options
author | Robert Newson <rnewson@apache.org> | 2011-11-07 23:49:20 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2011-11-08 11:24:50 +0000 |
commit | 6d912c9fe361203ee3245a4dc2ee2c2fdd9ce939 (patch) | |
tree | b33426d5c132335ab748eafa60ced263dd6b7204 | |
parent | c4c8d946177f856dd7a4b9cac352f1dd515ea7cd (diff) | |
download | couchdb-6d912c9fe361203ee3245a4dc2ee2c2fdd9ce939.tar.gz |
COUCHDB-1337 - Use attachments md5 as ETag if available
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | share/www/script/test/attachment_names.js | 2 | ||||
-rw-r--r-- | share/www/script/test/attachments.js | 2 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 5 |
5 files changed, 12 insertions, 3 deletions
@@ -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 ------------- @@ -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 ------------- diff --git a/share/www/script/test/attachment_names.js b/share/www/script/test/attachment_names.js index ced0ead0c..fb5f18f5c 100644 --- a/share/www/script/test/attachment_names.js +++ b/share/www/script/test/attachment_names.js @@ -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", diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js index 8f258adf1..a409f82de 100644 --- a/share/www/script/test/attachments.js +++ b/share/www/script/test/attachments.js @@ -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 = { diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 3d2d2c1f3..dad8705e5 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -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) |