diff options
-rw-r--r-- | share/www/script/couch.js | 30 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 20 | ||||
-rw-r--r-- | src/couchdb/couch_httpd.erl | 4 |
3 files changed, 30 insertions, 24 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js index 2f15737d..cf26bb2e 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -243,22 +243,22 @@ CouchDB.request = function(method, uri, options) { 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); } +} diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index b35e66ce..3d061ed5 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -682,10 +682,9 @@ var tests = { 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 @@ var tests = { 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"); diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index c745fdb8..bdc172a3 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -731,7 +731,7 @@ handle_attachment_request(Req, 'GET', _DbName, Db, DocId, FileName) -> {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 @@ handle_attachment_request(Req, Method, _DbName, Db, DocId, FileName) []; _ -> [{FileName, { - Req:get_header_value("Content-Type"), + list_to_binary(Req:get_header_value("Content-Type")), Req:recv_body() }}] end, |