summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/changes.js13
-rw-r--r--src/couchdb/couch_httpd_db.erl5
2 files changed, 15 insertions, 3 deletions
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index f5a3e149..d805d6cd 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -10,6 +10,12 @@
// License for the specific language governing permissions and limitations under
// the License.
+function jsonp(obj) {
+ T(jsonp_flag == 0);
+ T(obj.results.length == 1 && obj.last_seq==1)
+ jsonp_flag = 1;
+}
+
couchTests.changes = function(debug) {
var db = new CouchDB("test_suite_db");
db.deleteDb();
@@ -30,6 +36,13 @@ couchTests.changes = function(debug) {
T(resp.results.length == 1 && resp.last_seq==1)
T(resp.results[0].changes[0].rev == docFoo._rev)
+ // test with callback
+ var xhr = CouchDB.request("GET", "/test_suite_db/_changes?callback=jsonp");
+ T(xhr.status == 200);
+ jsonp_flag = 0;
+ eval(xhr.responseText);
+ T(jsonp_flag == 1);
+
req = CouchDB.request("GET", "/test_suite_db/_changes?continuous=true&timeout=10");
var resp = JSON.parse(req.responseText);
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 5d915d30..46410ff7 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -86,12 +86,11 @@ handle_changes_req(#httpd{method='GET',path_parts=[DbName|_]}=Req, Db) ->
couch_db_update_notifier:stop(Notify),
get_rest_db_updated() % clean out any remaining update messages
end;
-
"false" ->
{ok, {LastSeq, _Prepend}} =
send_changes(Req, Resp, Db, StartSeq, <<"">>),
send_chunk(Resp, io_lib:format("\n],\n\"last_seq\":~w}\n", [LastSeq])),
- send_chunk(Resp, "")
+ end_json_response(Resp)
end;
handle_changes_req(#httpd{path_parts=[_,<<"_changes">>]}=Req, _Db) ->
@@ -121,7 +120,7 @@ keep_sending_changes(#httpd{user_ctx=UserCtx,path_parts=[DbName|_]}=Req, Resp, D
keep_sending_changes(Req, Resp, Db2, EndSeq, Prepend2, Timeout, TimeoutFun);
stop ->
send_chunk(Resp, io_lib:format("\n],\n\"last_seq\":~w}\n", [EndSeq])),
- send_chunk(Resp, "")
+ end_json_response(Resp)
end.
send_changes(Req, Resp, Db, StartSeq, Prepend0) ->