couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r737304 - in /couchdb/trunk: share/server/main.js share/www/script/couch_tests.js src/couchdb/couch_httpd_external.erl
Date Sat, 24 Jan 2009 05:17:51 GMT
Author: jchris
Date: Sat Jan 24 05:17:50 2009
New Revision: 737304

URL: http://svn.apache.org/viewvc?rev=737304&view=rev
Log:
Improve show/list API and send external responses without chunked as it's not needed.

Modified:
    couchdb/trunk/share/server/main.js
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_httpd_external.erl

Modified: couchdb/trunk/share/server/main.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/server/main.js?rev=737304&r1=737303&r2=737304&view=diff
==============================================================================
--- couchdb/trunk/share/server/main.js [utf-8] (original)
+++ couchdb/trunk/share/server/main.js [utf-8] Sat Jan 24 05:17:50 2009
@@ -147,7 +147,7 @@
     var bestKey = keysByMime[bestMime];
     var rFunc = responders[bestKey];
     if (rFunc) {
-      var resp = rFunc();
+      var resp = maybeWrapResponse(rFunc());
       resp["headers"] = resp["headers"] || {};
       resp["headers"]["Content-Type"] = bestMime;
       return resp;
@@ -369,10 +369,19 @@
   }
 }
 
+function maybeWrapResponse(resp) {
+  var type = typeof resp;
+  if ((type == "string") || (type == "xml")) {
+    return {body:resp};
+  } else {
+    return resp;
+  }
+};
+
 function runRenderFunction(renderFun, args) {
   try {
-    var result = renderFun.apply(null, args);
-    respond(result); 
+    var resp = renderFun.apply(null, args);
+    respond(maybeWrapResponse(resp)); 
   } catch(e) {
     log("function raised error: "+e.toString());
     log("stacktrace: "+e.stack);

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=737304&r1=737303&r2=737304&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Sat Jan 24 05:17:50 2009
@@ -2610,19 +2610,21 @@
         acceptSwitch: stringFun(function(head, row, req) {
           return respondWith(req, {
             html : function() {
+              // If you're outputting text and you're not setting
+              // any headers, you can just return a string.
               if (head) {
-                return {body : "HTML <ul>"};
+                return "HTML <ul>";
               } else if (row) {
-                return {body : '\n<li>Key: '
-                  +row.key+' Value: '+row.value+'</li>'};
+                return '\n<li>Key: '
+                  +row.key+' Value: '+row.value+'</li>';
               } else { // tail
-                return {body : "</ul>"};
+                return "</ul>";
               }
             },
             xml : function() {
               if (head) {
-                return {body:'<feed xmlns="http://www.w3.org/2005/Atom">'
-                  +'<title>Test XML Feed</title>'};
+                return '<feed xmlns="http://www.w3.org/2005/Atom">'
+                  +'<title>Test XML Feed</title>';
               } else if (row) {
                 // Becase Safari can't stand to see that dastardly
                 // E4X outside of a string. Outside of tests you
@@ -2631,9 +2633,11 @@
                 entry.id = row.id;
                 entry.title = row.key;
                 entry.content = row.value;
-                return {body:entry};
+                // We'll also let you return just an E4X object
+                // if you aren't setting headers.
+                return entry;
               } else {
-                return {body : "</feed>"};
+                return "</feed>";
               }
             }
           })

Modified: couchdb/trunk/src/couchdb/couch_httpd_external.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_external.erl?rev=737304&r1=737303&r2=737304&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_external.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_external.erl Sat Jan 24 05:17:50 2009
@@ -96,9 +96,7 @@
         headers = Headers
     } = parse_external_response(Response),
     Resp = MochiReq:respond({Code, 
-        default_or_content_type(CType, Headers), chunked}),
-    Resp:write_chunk(Data),
-    Resp:write_chunk(""),
+        default_or_content_type(CType, Headers), Data}),
     {ok, Resp}.
 
 parse_external_response({Response}) ->



Mime
View raw message