summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Slater <nslater@apache.org>2009-02-24 18:10:19 +0000
committerNoah Slater <nslater@apache.org>2009-02-24 18:10:19 +0000
commit47895d920228edfb195e62ff04d5aa8ef667ed5b (patch)
tree062357f58cc657a7136d5af08940b2bcc1aab2ab
parentcb03fe83412bd514bdbfad0e7ac0da76be3bf372 (diff)
added newline to JSON responses, closes COUCHDB-107
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@747465 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/test/config.js7
-rw-r--r--share/www/script/test/content_negotiation.js4
-rw-r--r--src/couchdb/couch_httpd.erl4
3 files changed, 11 insertions, 4 deletions
diff --git a/share/www/script/test/config.js b/share/www/script/test/config.js
index a156be37..debe499a 100644
--- a/share/www/script/test/config.js
+++ b/share/www/script/test/config.js
@@ -15,7 +15,7 @@ couchTests.config = function(debug) {
db.deleteDb();
db.createDb();
if (debug) debugger;
-
+
// test that /_config returns all the settings
var xhr = CouchDB.request("GET", "/_config");
var config = JSON.parse(xhr.responseText);
@@ -49,7 +49,7 @@ couchTests.config = function(debug) {
T(config.httpd_global_handlers._config);
T(config.log.level);
T(config.query_servers.javascript);
-
+
// test that settings can be altered
xhr = CouchDB.request("PUT", "/_config/test/foo",{
body : JSON.stringify("bar"),
@@ -62,5 +62,6 @@ couchTests.config = function(debug) {
// you can get a single key
xhr = CouchDB.request("GET", "/_config/test/foo");
- T(xhr.responseText == '"bar"');
+ config = JSON.parse(xhr.responseText);
+ T(config == "bar");
};
diff --git a/share/www/script/test/content_negotiation.js b/share/www/script/test/content_negotiation.js
index 757105ff..9df79bcd 100644
--- a/share/www/script/test/content_negotiation.js
+++ b/share/www/script/test/content_negotiation.js
@@ -20,6 +20,10 @@ couchTests.content_negotiation = function(debug) {
xhr = CouchDB.request("GET", "/test_suite_db/");
T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
+ // make sure JSON responses end in a newline
+ var text = xhr.responseText;
+ T(text[text.length-1] == "\n");
+
xhr = CouchDB.request("GET", "/test_suite_db/", {
headers: {"Accept": "text/html;text/plain;*/*"}
});
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 9b175825..3365e88c 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -367,7 +367,8 @@ send_json(Req, Code, Headers, Value) ->
{"Content-Type", negotiate_content_type(Req)},
{"Cache-Control", "must-revalidate"}
],
- send_response(Req, Code, DefaultHeaders ++ Headers, ?JSON_ENCODE(Value)).
+ send_response(Req, Code, DefaultHeaders ++ Headers,
+ list_to_binary([?JSON_ENCODE(Value), $\n])).
start_json_response(Req, Code) ->
start_json_response(Req, Code, []).
@@ -380,6 +381,7 @@ start_json_response(Req, Code, Headers) ->
start_chunked_response(Req, Code, DefaultHeaders ++ Headers).
end_json_response(Resp) ->
+ send_chunk(Resp, [$\n]),
send_chunk(Resp, []).