From 9b83ec394c830ce4f01fa693179c01826859b6e0 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sat, 24 Jan 2009 05:17:50 +0000 Subject: Improve show/list API and send external responses without chunked as it's not needed. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@737304 13f79535-47bb-0310-9956-ffa450edef68 --- share/server/main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'share/server') diff --git a/share/server/main.js b/share/server/main.js index d2b9b7e0..8e1f91cd 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -147,7 +147,7 @@ respondWith = function(req, responders) { 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 @@ while (cmd = eval(readline())) { } } +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); -- cgit v1.2.3