couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1032289 - in /couchdb/branches/new_replicator: share/www/script/test/attachments_multipart.js src/couchdb/couch_httpd_db.erl
Date Sun, 07 Nov 2010 14:48:40 GMT
Author: fdmanana
Date: Sun Nov  7 14:48:40 2010
New Revision: 1032289

URL: http://svn.apache.org/viewvc?rev=1032289&view=rev
Log:
Merged revision 1032288 from trunk:

Allow the atts_since parameter to work together with the open_revs parameter.


Modified:
    couchdb/branches/new_replicator/share/www/script/test/attachments_multipart.js
    couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl

Modified: couchdb/branches/new_replicator/share/www/script/test/attachments_multipart.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/test/attachments_multipart.js?rev=1032289&r1=1032288&r2=1032289&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/test/attachments_multipart.js (original)
+++ couchdb/branches/new_replicator/share/www/script/test/attachments_multipart.js Sun Nov
 7 14:48:40 2010
@@ -115,8 +115,11 @@ couchTests.attachments_multipart= functi
   // now test receiving multipart docs
   
   function getBoundary(xhr) {
-    var ctype = xhr.getResponseHeader("Content-Type");
-  
+    if (xhr instanceof XMLHttpRequest) {
+      var ctype = xhr.getResponseHeader("Content-Type");
+    } else {
+      var ctype = xhr.headers['Content-Type'];
+    }
     var ctypeArgs = ctype.split("; ").slice(1);
     var boundary = null;
     for(var i=0; i<ctypeArgs.length; i++) {
@@ -134,7 +137,11 @@ couchTests.attachments_multipart= functi
   
   function parseMultipart(xhr) {
     var boundary = getBoundary(xhr);
-    var mimetext = xhr.responseText;
+    if (xhr instanceof XMLHttpRequest) {
+      var mimetext = xhr.responseText;
+    } else {
+      var mimetext = xhr.body;
+    }
     // strip off leading boundary
     var leading = "--" + boundary + "\r\n";
     var last = "\r\n--" + boundary + "--";
@@ -207,7 +214,34 @@ couchTests.attachments_multipart= functi
   T(doc._attachments['bar.txt'].follows == true);
   
   T(sections[1].body == "this is 18 chars l");
-  
+
+  // try the atts_since parameter together with the open_revs parameter
+  xhr = CouchDB.request(
+    "GET",
+    '/test_suite_db/multipart?open_revs=["' +
+      doc._rev + '"]&atts_since=["' + firstrev + '"]',
+    {headers: {"accept": "multipart/mixed"}}
+  );
+
+  T(xhr.status === 200);
+
+  sections = parseMultipart(xhr);
+  // 1 section, with a multipart/related Content-Type
+  T(sections.length === 1);
+  T(sections[0].headers['Content-Type'].indexOf('multipart/related;') === 0);
+
+  var innerSections = parseMultipart(sections[0]);
+  // 2 inner sections: a document body section plus an attachment data section
+  T(innerSections.length === 2);
+  T(innerSections[0].headers['content-type'] === 'application/json');
+
+  doc = JSON.parse(innerSections[0].body);
+
+  T(doc._attachments['foo.txt'].stub === true);
+  T(doc._attachments['bar.txt'].follows === true);
+
+  T(innerSections[1].body === "this is 18 chars l");
+
   // try it with a rev that doesn't exist (should get all attachments)
   
   xhr = CouchDB.request("GET", "/test_suite_db/multipart?atts_since=[\"1-2897589\"]",

Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl?rev=1032289&r1=1032288&r2=1032289&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl Sun Nov  7 14:48:40 2010
@@ -559,18 +559,19 @@ db_doc_req(#httpd{method='GET'}=Req, Db,
     #doc_query_args{
         rev = Rev,
         open_revs = Revs,
-        options = Options,
+        options = Options1,
         atts_since = AttsSince
     } = parse_doc_query(Req),
+    Options = case AttsSince of
+    nil ->
+        Options1;
+    RevList when is_list(RevList) ->
+        [{atts_since, RevList}, attachments | Options1]
+    end,
     case Revs of
     [] ->
-        Options2 =
-        if AttsSince /= nil ->
-            [{atts_since, AttsSince}, attachments | Options];
-        true -> Options
-        end,
-        Doc = couch_doc_open(Db, DocId, Rev, Options2),
-        send_doc(Req, Doc, Options2);
+        Doc = couch_doc_open(Db, DocId, Rev, Options),
+        send_doc(Req, Doc, Options);
     _ ->
         {ok, Results} = couch_db:open_doc_revs(Db, DocId, Revs, Options),
         AcceptedTypes = case couch_httpd:header_value(Req, "Accept") of



Mime
View raw message