From 4b079e27429567b520abf091a8c0da84885c0d80 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Thu, 24 Jun 2010 05:21:30 +0000 Subject: use JSON content type in replicator, require it in the _bulk_docs and other POST apis git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957422 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch.js | 2 ++ share/www/script/test/basics.js | 9 +++++++-- share/www/script/test/batch_save.js | 5 ++++- share/www/script/test/stats.js | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) (limited to 'share/www/script') diff --git a/share/www/script/couch.js b/share/www/script/couch.js index dbffa7ce..d745b06e 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -398,6 +398,8 @@ CouchDB.newXhr = function() { CouchDB.request = function(method, uri, options) { options = options || {}; + options.headers = options.headers || {}; + options.headers["Content-Type"] = options.headers["Content-Type"] || "application/json"; var req = CouchDB.newXhr(); if(uri.substr(0, "http://".length) != "http://") { uri = CouchDB.urlPrefix + uri diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js index 0f9ac44f..6a3ae471 100644 --- a/share/www/script/test/basics.js +++ b/share/www/script/test/basics.js @@ -152,7 +152,8 @@ couchTests.basics = function(debug) { // test that the POST response has a Location header var xhr = CouchDB.request("POST", "/test_suite_db", { - body: JSON.stringify({"foo":"bar"}) + body: JSON.stringify({"foo":"bar"}), + headers: {"Content-Type": "application/json"} }); var resp = JSON.parse(xhr.responseText); T(resp.ok); @@ -164,6 +165,7 @@ couchTests.basics = function(debug) { // test that that POST's with an _id aren't overriden with a UUID. var xhr = CouchDB.request("POST", "/test_suite_db", { + headers: {"Content-Type": "application/json"}, body: JSON.stringify({"_id": "oppossum", "yar": "matey"}) }); var resp = JSON.parse(xhr.responseText); @@ -202,7 +204,10 @@ couchTests.basics = function(debug) { result = JSON.parse(xhr.responseText); T(result.error == "doc_validation"); - xhr = CouchDB.request("POST", "/test_suite_db/", {body: data}); + xhr = CouchDB.request("POST", "/test_suite_db/", { + headers: {"Content-Type": "application/json"}, + body: data + }); T(xhr.status == 500); result = JSON.parse(xhr.responseText); T(result.error == "doc_validation"); diff --git a/share/www/script/test/batch_save.js b/share/www/script/test/batch_save.js index 1c8a2be9..a1b00192 100644 --- a/share/www/script/test/batch_save.js +++ b/share/www/script/test/batch_save.js @@ -36,7 +36,10 @@ couchTests.batch_save = function(debug) { // repeat the tests for POST for(i=0; i < 100; i++) { - var resp = db.request("POST", db.uri + "?batch=ok", {body: JSON.stringify({a:1})}); + var resp = db.request("POST", db.uri + "?batch=ok", { + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({a:1}) + }); T(JSON.parse(resp.responseText).ok); } diff --git a/share/www/script/test/stats.js b/share/www/script/test/stats.js index 23468a37..d2fd6eac 100644 --- a/share/www/script/test/stats.js +++ b/share/www/script/test/stats.js @@ -160,7 +160,10 @@ couchTests.stats = function(debug) { runTest("couchdb", "database_writes", { run: function(db) { - CouchDB.request("POST", "/test_suite_db", {body: '{"a": "1"}'}) + CouchDB.request("POST", "/test_suite_db", { + headers: {"Content-Type": "application/json"}, + body: '{"a": "1"}' + }) }, test: function(before, after) { TEquals(before+1, after, "POST'ing new docs increments doc writes."); -- cgit v1.2.3