You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2010/05/19 23:20:25 UTC
svn commit: r946404 - in /couchdb/branches/0.11.x: ./
etc/couchdb/default.ini.tpl.in etc/default/couchdb
share/www/script/test/changes.js share/www/script/test/jsonp.js
src/couchdb/couch_httpd.erl
Author: jchris
Date: Wed May 19 21:20:25 2010
New Revision: 946404
URL: http://svn.apache.org/viewvc?rev=946404&view=rev
Log:
backport r946400 (jsonp config) from trunk
Modified:
couchdb/branches/0.11.x/ (props changed)
couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
couchdb/branches/0.11.x/etc/default/couchdb (props changed)
couchdb/branches/0.11.x/share/www/script/test/changes.js
couchdb/branches/0.11.x/share/www/script/test/jsonp.js
couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl
Propchange: couchdb/branches/0.11.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May 19 21:20:25 2010
@@ -6,4 +6,4 @@
/couchdb/branches/list-iterator:782292-784593
/couchdb/branches/tail_header:775760-778477
/couchdb/tags/0.10.0:825400
-/couchdb/trunk:909247,910054,910696,910910-910911,911544,911559,911578,911602,911717,911837,912474,912606,912608,912615,912636,915526,915529-915530,915827,916076,916153,916518,916521,917553,918855,919193,921707,923526,925264,931655,933039,936889,941451
+/couchdb/trunk:909247,910054,910696,910910-910911,911544,911559,911578,911602,911717,911837,912474,912606,912608,912615,912636,915526,915529-915530,915827,916076,916153,916518,916521,917553,918855,919193,921707,923526,925264,931655,933039,936889,941451,946400
Modified: couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in?rev=946404&r1=946403&r2=946404&view=diff
==============================================================================
--- couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in Wed May 19 21:20:25 2010
@@ -18,6 +18,7 @@ bind_address = 127.0.0.1
authentication_handlers = {couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
default_handler = {couch_httpd_db, handle_request}
secure_rewrites = true
+jsonp = false
[log]
file = %localstatelogdir%/couch.log
Propchange: couchdb/branches/0.11.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May 19 21:20:25 2010
@@ -6,5 +6,5 @@
/couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
/couchdb/branches/tail_header/etc/default/couchdb:775760-778477
/couchdb/tags/0.10.0/etc/default/couchdb:825400
-/couchdb/trunk/etc/default/couchdb:909247,910054,910696,911544,911602,911717,911837,912474,912606,912608,912615,912636,915526,915529-915530,915827,916076,916153,916518,916521,917553,918855,919193,921707,923526,925264,931655,933039,936889,941451
+/couchdb/trunk/etc/default/couchdb:909247,910054,910696,911544,911602,911717,911837,912474,912606,912608,912615,912636,915526,915529-915530,915827,916076,916153,916518,916521,917553,918855,919193,921707,923526,925264,931655,933039,936889,941451,946400
/incubator/couchdb/trunk/etc/default/couchdb:642419-694440
Modified: couchdb/branches/0.11.x/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/changes.js?rev=946404&r1=946403&r2=946404&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/changes.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/changes.js Wed May 19 21:20:25 2010
@@ -37,12 +37,18 @@ couchTests.changes = function(debug) {
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);
-
+
+ run_on_modified_server(
+ [{section: "httpd",
+ key: "jsonp",
+ value: "true"}],
+ function() {
+ 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?feed=continuous&timeout=10");
var lines = req.responseText.split("\n");
Modified: couchdb/branches/0.11.x/share/www/script/test/jsonp.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/jsonp.js?rev=946404&r1=946403&r2=946404&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/jsonp.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/jsonp.js Wed May 19 21:20:25 2010
@@ -32,38 +32,51 @@ couchTests.jsonp = function(debug) {
db.deleteDb();
db.createDb();
if (debug) debugger;
-
+
var doc = {_id:"0",a:0,b:0};
T(db.save(doc).ok);
+
+ // callback param is ignored unless jsonp is configured
+ var xhr = CouchDB.request("GET", "/test_suite_db/0?callback=jsonp_not_configured");
+ JSON.parse(xhr.responseText);
- // Test unchunked callbacks.
- var xhr = CouchDB.request("GET", "/test_suite_db/0?callback=jsonp_no_chunk");
- T(xhr.status == 200);
- jsonp_flag = 0;
- eval(xhr.responseText);
- T(jsonp_flag == 1);
- xhr = CouchDB.request("GET", "/test_suite_db/0?callback=foo\"");
- T(xhr.status == 400);
+ run_on_modified_server(
+ [{section: "httpd",
+ key: "jsonp",
+ value: "true"}],
+ function() {
- // Test chunked responses
- var doc = {_id:"1",a:1,b:1};
- T(db.save(doc).ok);
+ // Test unchunked callbacks.
+ var xhr = CouchDB.request("GET", "/test_suite_db/0?callback=jsonp_no_chunk");
+ T(xhr.status == 200);
+ jsonp_flag = 0;
+ eval(xhr.responseText);
+ T(jsonp_flag == 1);
+ xhr = CouchDB.request("GET", "/test_suite_db/0?callback=foo\"");
+ T(xhr.status == 400);
+
+ // Test chunked responses
+ var doc = {_id:"1",a:1,b:1};
+ T(db.save(doc).ok);
- var designDoc = {
- _id:"_design/test",
- language: "javascript",
- views: {
- all_docs: {map: "function(doc) {if(doc.a) emit(null, doc.a);}"}
+ var designDoc = {
+ _id:"_design/test",
+ language: "javascript",
+ views: {
+ all_docs: {map: "function(doc) {if(doc.a) emit(null, doc.a);}"}
+ }
}
- }
- T(db.save(designDoc).ok);
+ T(db.save(designDoc).ok);
+
+ var url = "/test_suite_db/_design/test/_view/all_docs?callback=jsonp_chunk";
+ xhr = CouchDB.request("GET", url);
+ T(xhr.status == 200);
+ jsonp_flag = 0;
+ eval(xhr.responseText);
+ T(jsonp_flag == 1);
+ xhr = CouchDB.request("GET", url + "\'");
+ T(xhr.status == 400);
+ });
+
- var url = "/test_suite_db/_design/test/_view/all_docs?callback=jsonp_chunk";
- xhr = CouchDB.request("GET", url);
- T(xhr.status == 200);
- jsonp_flag = 0;
- eval(xhr.responseText);
- T(jsonp_flag == 1);
- xhr = CouchDB.request("GET", url + "\'");
- T(xhr.status == 400);
};
Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl?rev=946404&r1=946403&r2=946404&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl Wed May 19 21:20:25 2010
@@ -573,8 +573,18 @@ start_jsonp(Req) ->
[] -> [];
CallBack ->
try
- validate_callback(CallBack),
- CallBack ++ "("
+ % make sure jsonp is configured on (default off)
+ case couch_config:get("httpd", "jsonp", "false") of
+ "true" ->
+ validate_callback(CallBack),
+ CallBack ++ "(";
+ _Else ->
+ % this could throw an error message, but instead we just ignore the
+ % jsonp parameter
+ % throw({bad_request, <<"JSONP must be configured before using.">>})
+ put(jsonp, no_jsonp),
+ []
+ end
catch
Error ->
put(jsonp, no_jsonp),