couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r693435 - in /incubator/couchdb/trunk: share/www/script/couch.js share/www/script/couch_tests.js src/couchdb/couch_httpd.erl
Date Tue, 09 Sep 2008 11:12:37 GMT
Author: cmlenz
Date: Tue Sep  9 04:12:36 2008
New Revision: 693435

URL: http://svn.apache.org/viewvc?rev=693435&view=rev
Log:
Fix for attachment content-type conversion from/to binary in RESTful API.

Modified:
    incubator/couchdb/trunk/share/www/script/couch.js
    incubator/couchdb/trunk/share/www/script/couch_tests.js
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: incubator/couchdb/trunk/share/www/script/couch.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch.js?rev=693435&r1=693434&r2=693435&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch.js [utf-8] Tue Sep  9 04:12:36 2008
@@ -243,22 +243,22 @@
 CouchDB.uuids_cache = [];
 
 CouchDB.newUuids = function(n) {
-    if (CouchDB.uuids_cache.length >= n) {
-      var uuids = CouchDB.uuids_cache.slice(CouchDB.uuids_cache.length - n);
-      if(CouchDB.uuids_cache.length - n == 0) {
-        CouchDB.uuids_cache = [];
-      } else {
-        CouchDB.uuids_cache =
-            CouchDB.uuids_cache.slice(0, CouchDB.uuids_cache.length - n);
-      }
-      return uuids;
+  if (CouchDB.uuids_cache.length >= n) {
+    var uuids = CouchDB.uuids_cache.slice(CouchDB.uuids_cache.length - n);
+    if(CouchDB.uuids_cache.length - n == 0) {
+      CouchDB.uuids_cache = [];
     } else {
-      var req = CouchDB.request("POST", "/_uuids?count=" + (100 + n));
-      var result = JSON.parse(req.responseText);
-      if (req.status != 200)
-        throw result;
       CouchDB.uuids_cache =
-          CouchDB.uuids_cache.concat(result.uuids.slice(0, 100));
-      return result.uuids.slice(100);
+          CouchDB.uuids_cache.slice(0, CouchDB.uuids_cache.length - n);
     }
+    return uuids;
+  } else {
+    var req = CouchDB.request("POST", "/_uuids?count=" + (100 + n));
+    var result = JSON.parse(req.responseText);
+    if (req.status != 200)
+      throw result;
+    CouchDB.uuids_cache =
+        CouchDB.uuids_cache.concat(result.uuids.slice(0, 100));
+    return result.uuids.slice(100);
   }
+}

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=693435&r1=693434&r2=693435&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Tue Sep  9 04:12:36 2008
@@ -682,10 +682,9 @@
     T(xhr.responseText == "This is a base64 encoded text");
     T(xhr.getResponseHeader("Content-Type") == "text/plain");
 
-
     // empty attachment
     var binAttDoc2 = {
-      _id: "bin_doc5",
+      _id: "bin_doc2",
       _attachments:{
         "foo.txt": {
           content_type:"text/plain",
@@ -696,19 +695,26 @@
 
     T(db.save(binAttDoc2).ok);
 
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc5/foo.txt");
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc2/foo.txt");
     T(xhr.responseText.length == 0);
     T(xhr.getResponseHeader("Content-Type") == "text/plain");
-       
+
     // test RESTful doc API
-    
-    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc2/foo2.txt", {
+
+    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc2/foo2.txt?rev=" + binAttDoc2._rev,
{
       body:"This is no base64 encoded text",
       headers:{"Content-Type": "text/plain;charset=utf-8"}
     });
     T(xhr.status == 201);
     var rev = JSON.parse(xhr.responseText).rev;
-    
+
+    binAttDoc2 = db.open("bin_doc2");
+    console.log(JSON.stringify(binAttDoc2));
+    T(binAttDoc2._attachments["foo.txt"] !== undefined);
+    T(binAttDoc2._attachments["foo2.txt"] !== undefined);
+    T(binAttDoc2._attachments["foo2.txt"].content_type == "text/plain;charset=utf-8");
+    T(binAttDoc2._attachments["foo2.txt"].length == 30);
+
     var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc2/foo2.txt");
     T(xhr.responseText == "This is no base64 encoded text");
     T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=693435&r1=693434&r2=693435&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Tue Sep  9 04:12:36 2008
@@ -731,7 +731,7 @@
         {Type, Bin} ->
             Resp = Req:respond({200, [
                 {"Cache-Control", "must-revalidate"},
-                {"Content-Type", Type},
+                {"Content-Type", binary_to_list(Type)},
                 {"Content-Length", integer_to_list(couch_doc:bin_size(Bin))}
             ] ++ server_header(), chunked}),
             couch_doc:bin_foldl(Bin,
@@ -756,7 +756,7 @@
             [];
         _ ->
             [{FileName, {
-                Req:get_header_value("Content-Type"),
+                list_to_binary(Req:get_header_value("Content-Type")),
                 Req:recv_body()
             }}]
     end,



Mime
View raw message