summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeks Keksov <keksov@gmail.com>2012-10-25 00:29:02 +0200
committerDave Cottlehuber <dch@apache.org>2012-10-25 00:29:02 +0200
commit07a6af222247d34c41ee8eabec9822c26a407ff8 (patch)
treea21b42e63f92e99d6602d392d25596e3ef28c5fc
parent67ae11292cd8c1e270f82dac16dc121376f1fb51 (diff)
downloadcouchdb-07a6af222247d34c41ee8eabec9822c26a407ff8.tar.gz
COUCHDB-1563 ensures urlPrefix is set in all ajax requests
-rw-r--r--share/www/script/couch.js11
-rw-r--r--share/www/script/test/changes.js17
-rw-r--r--share/www/script/test/content_negotiation.js2
-rw-r--r--share/www/verify_install.html1
4 files changed, 18 insertions, 13 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index f7099e3f0..3deb44102 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -400,15 +400,20 @@ CouchDB.xhrheader = function(xhr, header) {
}
}
+CouchDB.proxyUrl = function(uri) {
+ if(uri.substr(0, CouchDB.protocol.length) != CouchDB.protocol) {
+ uri = CouchDB.urlPrefix + uri;
+ }
+ return uri;
+}
+
CouchDB.request = function(method, uri, options) {
options = typeof(options) == 'object' ? options : {};
options.headers = typeof(options.headers) == 'object' ? options.headers : {};
options.headers["Content-Type"] = options.headers["Content-Type"] || options.headers["content-type"] || "application/json";
options.headers["Accept"] = options.headers["Accept"] || options.headers["accept"] || "application/json";
var req = CouchDB.newXhr();
- if(uri.substr(0, CouchDB.protocol.length) != CouchDB.protocol) {
- uri = CouchDB.urlPrefix + uri;
- }
+ uri = CouchDB.proxyUrl(uri);
req.open(method, uri, false);
if (options.headers) {
var headers = options.headers;
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index 33b3af993..d76c19378 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -78,7 +78,7 @@ couchTests.changes = function(debug) {
// WebKit (last checked on nightly #47686) does fail on processing
// the async-request properly while javascript is executed.
- xhr.open("GET", "/test_suite_db/_changes?feed=continuous&timeout=500", true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&timeout=500"), true);
xhr.send("");
var docBar = {_id:"bar", bar:1};
@@ -122,7 +122,7 @@ couchTests.changes = function(debug) {
xhr = CouchDB.newXhr();
//verify the hearbeat newlines are sent
- xhr.open("GET", "/test_suite_db/_changes?feed=continuous&heartbeat=10&timeout=500", true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&heartbeat=10&timeout=500"), true);
xhr.send("");
var str;
@@ -169,7 +169,7 @@ couchTests.changes = function(debug) {
// test longpolling
xhr = CouchDB.newXhr();
- xhr.open("GET", "/test_suite_db/_changes?feed=longpoll", true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=longpoll"), true);
xhr.send("");
waitForSuccess(function() {
@@ -181,7 +181,7 @@ couchTests.changes = function(debug) {
xhr = CouchDB.newXhr();
- xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=3", true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=longpoll&since=3"), true);
xhr.send("");
var docBarz = {_id:"barz", bar:1};
@@ -300,13 +300,13 @@ couchTests.changes = function(debug) {
// filter with longpoll
// longpoll filters full history when run without a since seq
xhr = CouchDB.newXhr();
- xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop", false);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop"), false);
xhr.send("");
var resp = JSON.parse(xhr.responseText);
T(resp.last_seq == 8);
// longpoll waits until a matching change before returning
xhr = CouchDB.newXhr();
- xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=8&filter=changes_filter/bop", true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=longpoll&since=7&filter=changes_filter/bop"), true);
xhr.send("");
db.save({"_id":"falsy", "bop" : ""}); // empty string is falsy
db.save({"_id":"bingo","bop" : "bingo"});
@@ -325,7 +325,7 @@ couchTests.changes = function(debug) {
// filter with continuous
xhr = CouchDB.newXhr();
- xhr.open("GET", "/test_suite_db/_changes?feed=continuous&filter=changes_filter/bop&timeout="+timeout, true);
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&filter=changes_filter/bop&timeout="+timeout), true);
xhr.send("");
db.save({"_id":"rusty", "bop" : "plankton"});
@@ -518,7 +518,7 @@ couchTests.changes = function(debug) {
if (!is_safari && xhr) {
// filter docids with continuous
xhr = CouchDB.newXhr();
- xhr.open("POST", "/test_suite_db/_changes?feed=continuous&timeout=500&since=7&filter=_doc_ids", true);
+ xhr.open("POST", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&timeout=500&since=7&filter=_doc_ids"), true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(options.body);
@@ -612,4 +612,3 @@ couchTests.changes = function(debug) {
// cleanup
db.deleteDb();
};
-
diff --git a/share/www/script/test/content_negotiation.js b/share/www/script/test/content_negotiation.js
index 5778fad2e..36e7dfbd3 100644
--- a/share/www/script/test/content_negotiation.js
+++ b/share/www/script/test/content_negotiation.js
@@ -19,7 +19,7 @@ couchTests.content_negotiation = function(debug) {
// with no accept header
var req = CouchDB.newXhr();
- req.open("GET", "/test_suite_db/", false);
+ req.open("GET", CouchDB.proxyUrl("/test_suite_db/"), false);
req.send("");
TEquals("text/plain; charset=utf-8", req.getResponseHeader("Content-Type"));
diff --git a/share/www/verify_install.html b/share/www/verify_install.html
index 1806adfe8..388833bd9 100644
--- a/share/www/verify_install.html
+++ b/share/www/verify_install.html
@@ -45,6 +45,7 @@ specific language governing permissions and limitations under the License.
}
function tests() {
+ CouchDB.urlPrefix = "..";
var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
// cleanup, ignore the 404