couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [3/3] git commit: COUCHDB-1337 - Use attachments md5 as ETag if available
Date Tue, 08 Nov 2011 11:26:30 GMT
COUCHDB-1337 - Use attachments md5 as ETag if available


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

Branch: refs/heads/master
Commit: 6d912c9fe361203ee3245a4dc2ee2c2fdd9ce939
Parents: c4c8d94
Author: Robert Newson <rnewson@apache.org>
Authored: Mon Nov 7 23:49:20 2011 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Nov 8 11:24:50 2011 +0000

----------------------------------------------------------------------
 CHANGES                                   |    3 +++
 NEWS                                      |    3 +++
 share/www/script/test/attachment_names.js |    2 +-
 share/www/script/test/attachments.js      |    2 +-
 src/couchdb/couch_httpd_db.erl            |    5 ++++-
 5 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/6d912c9f/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 59ebe5f..7d9d46e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
 -------------
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6d912c9f/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index 662f033..a11f511 100644
--- a/NEWS
+++ b/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
 -------------
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6d912c9f/share/www/script/test/attachment_names.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachment_names.js b/share/www/script/test/attachment_names.js
index ced0ead..fb5f18f 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",

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6d912c9f/share/www/script/test/attachments.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js
index 8f258ad..a409f82 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 = {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6d912c9f/src/couchdb/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 3d2d2c1..dad8705 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)


Mime
View raw message