summaryrefslogtreecommitdiff
path: root/share/www/script/test/list_views.js
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-08-05 04:09:11 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-08-05 04:09:11 +0000
commit4ae77952e4f2453425d3ad0a85a453ca102b322f (patch)
tree93ab4c114206b0640d9d99903f16c7a69f7adb04 /share/www/script/test/list_views.js
parent9cddd68f4648620be9d81aedc125704e1824cf2d (diff)
Upgraded JavaScript Accept header handling to make it useful.
After user@ thread with Adam Jacob [1] http://tinyurl.com/kuhl2j I realized that giving users the option to set a server preference of mime-types was crucial. Without ordering, you see nasty side effects like a browser getting an Atom feed by default. With ordering, you can ensure that browsers get HTML, API clients see XML, and Ajax apps use JSON in a no-hassle way. Example new API: function(doc, req) { provides("html", function() { return "Hello " + doc.name + "."; }); provides("xml", function() { var xml = new XML('<xml></xml>'); xml.hello = doc.name; return xml; } }; If a client sends an Accept header like "application/xml, text/html" this will return html. If the client sends just "application/xml" they will get xml. respondsWith() has been removed. I don't think it's worth the cost to maintain a parallel implementation just to be deprecated as buggy. This patch also continues us on the path to a cleaner, more organized query server. Cheers and enjoy. [1] http://mail-archives.apache.org/mod_mbox/couchdb-user/200907.mbox/%3cb8602b350907241906l7c7f97fdg9d78facacd8605fd@mail.gmail.com%3e git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@801056 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/test/list_views.js')
-rw-r--r--share/www/script/test/list_views.js73
1 files changed, 35 insertions, 38 deletions
diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js
index 4b089bac..5871e10e 100644
--- a/share/www/script/test/list_views.js
+++ b/share/www/script/test/list_views.js
@@ -83,34 +83,33 @@ couchTests.list_views = function(debug) {
}),
acceptSwitch: stringFun(function(head, req) {
// respondWith takes care of setting the proper headers
- respondWith(req, {
- html : function() {
- send("HTML <ul>");
-
- var row, num = 0;
- while (row = getRow()) {
- num ++;
- send('\n<li>Key: '
- +row.key+' Value: '+row.value
- +' LineNo: '+num+'</li>');
- }
-
- // tail
- return '</ul>';
- },
- xml : function() {
- send('<feed xmlns="http://www.w3.org/2005/Atom">'
- +'<title>Test XML Feed</title>');
-
- while (row = getRow()) {
- var entry = new XML('<entry/>');
- entry.id = row.id;
- entry.title = row.key;
- entry.content = row.value;
- send(entry);
- }
- return "</feed>";
+ provides("html", function() {
+ send("HTML <ul>");
+
+ var row, num = 0;
+ while (row = getRow()) {
+ num ++;
+ send('\n<li>Key: '
+ +row.key+' Value: '+row.value
+ +' LineNo: '+num+'</li>');
}
+
+ // tail
+ return '</ul>';
+ });
+
+ provides("xml", function() {
+ send('<feed xmlns="http://www.w3.org/2005/Atom">'
+ +'<title>Test XML Feed</title>');
+
+ while (row = getRow()) {
+ var entry = new XML('<entry/>');
+ entry.id = row.id;
+ entry.title = row.key;
+ entry.content = row.value;
+ send(entry);
+ }
+ return "</feed>";
});
}),
qsParams: stringFun(function(head, req) {
@@ -127,17 +126,15 @@ couchTests.list_views = function(debug) {
return " tail";
}),
stopIter2: stringFun(function(head, req) {
- respondWith(req, {
- html: function() {
- send("head");
- var row, row_number = 0;
- while(row = getRow()) {
- if(row_number > 2) break;
- send(" " + row_number);
- row_number += 1;
- };
- return " tail";
- }
+ provides("html", function() {
+ send("head");
+ var row, row_number = 0;
+ while(row = getRow()) {
+ if(row_number > 2) break;
+ send(" " + row_number);
+ row_number += 1;
+ };
+ return " tail";
});
}),
tooManyGetRows : stringFun(function() {