couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [2/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/2f6743b3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2f6743b3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2f6743b3

Branch: refs/heads/1.1.x
Commit: 2f6743b3ab419640d4b69a77d10ddf0604c9687a
Parents: e721e2d
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:25:23 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/2f6743b3/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 9d82ecd..762d574 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,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/2f6743b3/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index 85eec13..7327c18 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,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/2f6743b3/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 777b5ec..78c95de 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/2f6743b3/share/www/script/test/attachments.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js
index b0cfd2c..d33600e 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/2f6743b3/src/couchdb/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index d763d3b..4872924 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -955,7 +955,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