You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2011/11/08 12:26:30 UTC

[1/3] git commit: COUCHDB-1337 - Use attachments md5 as ETag if available

Updated Branches:
  refs/heads/1.1.x e721e2d22 -> 2f6743b3a
  refs/heads/1.2.x a2b8fe09d -> 22d798888
  refs/heads/master c4c8d9461 -> 6d912c9fe


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/22d79888
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/22d79888
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/22d79888

Branch: refs/heads/1.2.x
Commit: 22d79888860d724e3b043a70229b5ed344441a6a
Parents: a2b8fe0
Author: Robert Newson <rn...@apache.org>
Authored: Mon Nov 7 23:49:20 2011 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Nov 8 11:25:44 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/22d79888/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e25f4f4..2821a7a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -63,6 +63,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/22d79888/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index d0f0338..e900796 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,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/22d79888/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/22d79888/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/22d79888/src/couchdb/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index f490364..ff4d3ec 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -970,7 +970,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)