couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r796207 - in /couchdb/trunk: share/www/script/test/changes.js src/couchdb/couch_httpd_db.erl
Date Tue, 21 Jul 2009 09:18:07 GMT
Author: jan
Date: Tue Jul 21 09:18:07 2009
New Revision: 796207

URL: http://svn.apache.org/viewvc?rev=796207&view=rev
Log:
Close jsonp response for _changes requests. Patch by Benoit Chesneau. Closes COUCHDB-418.

Modified:
    couchdb/trunk/share/www/script/test/changes.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/changes.js?rev=796207&r1=796206&r2=796207&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/changes.js (original)
+++ couchdb/trunk/share/www/script/test/changes.js Tue Jul 21 09:18:07 2009
@@ -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 @@
   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);

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=796207&r1=796206&r2=796207&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Tue Jul 21 09:18:07 2009
@@ -86,12 +86,11 @@
             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(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) ->



Mime
View raw message