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/05/27 00:27:36 UTC

svn commit: r1128111 - in /couchdb/branches/1.0.x: share/www/script/test/attachments.js src/couchdb/couch_httpd_db.erl

Author: rnewson
Date: Thu May 26 22:27:36 2011
New Revision: 1128111

URL: http://svn.apache.org/viewvc?rev=1128111&view=rev
Log:
COUCHDB-1173 - return Content-MD5 when fetching attachments where possible.

Conflicts:

	src/couchdb/couch_httpd_db.erl

Modified:
    couchdb/branches/1.0.x/share/www/script/test/attachments.js
    couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl

Modified: couchdb/branches/1.0.x/share/www/script/test/attachments.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/attachments.js?rev=1128111&r1=1128110&r2=1128111&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/attachments.js (original)
+++ couchdb/branches/1.0.x/share/www/script/test/attachments.js Thu May 26 22:27:36 2011
@@ -270,4 +270,17 @@ couchTests.attachments= function(debug) 
   } catch (e) {
       T(e.error == "missing_stub");
   }
+
+  // test MD5 header
+  var bin_data = "foo bar"
+  var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc7/attachment.txt", {
+    headers:{"Content-Type":"application/octet-stream",
+             "Content-MD5":"MntvB0NYESObxH4VRDUycw=="},
+    body:bin_data
+  });
+  TEquals(201, xhr.status);
+
+  var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc7/attachment.txt");
+  TEquals('MntvB0NYESObxH4VRDUycw==', xhr.getResponseHeader("Content-MD5"));
+
 };

Modified: couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl?rev=1128111&r1=1128110&r2=1128111&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl Thu May 26 22:27:36 2011
@@ -928,6 +928,11 @@ db_attachment_req(#httpd{method='GET'}=R
             [{"Content-Encoding", atom_to_list(Enc)}];
         _ ->
             []
+        end ++ if
+            Enc =:= identity orelse ReqAcceptsAttEnc =:= true ->
+                [{"Content-MD5", base64:encode(Att#att.md5)}];
+            true ->
+                []
         end,
         Len = case {Enc, ReqAcceptsAttEnc} of
         {identity, _} ->