couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] git commit: support JSONP in externals
Date Thu, 07 Feb 2013 22:49:14 GMT
support JSONP in externals

COUCHDB-1313


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/35739526
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/35739526
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/35739526

Branch: refs/heads/1.3.x
Commit: 35739526745fe5069aafa51f35a1f3a470683f64
Parents: 8848b5d
Author: Robert Newson <rnewson@apache.org>
Authored: Thu Oct 20 16:17:22 2011 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Feb 7 22:44:27 2013 +0000

----------------------------------------------------------------------
 src/couchdb/couch_db.hrl             |    3 ++-
 src/couchdb/couch_httpd_external.erl |   18 +++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/35739526/src/couchdb/couch_db.hrl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl
index 3b08de8..f79e5f7 100644
--- a/src/couchdb/couch_db.hrl
+++ b/src/couchdb/couch_db.hrl
@@ -241,7 +241,8 @@
     stop = false,
     data = <<>>,
     ctype = "application/json",
-    headers = []
+    headers = [],
+    json = nil
 }).
 
 -record(index_header,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/35739526/src/couchdb/couch_httpd_external.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_external.erl b/src/couchdb/couch_httpd_external.erl
index bfe77a3..2036d25 100644
--- a/src/couchdb/couch_httpd_external.erl
+++ b/src/couchdb/couch_httpd_external.erl
@@ -120,17 +120,21 @@ json_query_keys([{<<"key">>, Value} | Rest], Acc) ->
 json_query_keys([Term | Rest], Acc) ->
     json_query_keys(Rest, [Term|Acc]).
 
-send_external_response(#httpd{mochi_req=MochiReq}=Req, Response) ->
+send_external_response(Req, Response) ->
     #extern_resp_args{
         code = Code,
         data = Data,
         ctype = CType,
-        headers = Headers
+        headers = Headers,
+        json = Json
     } = parse_external_response(Response),
-    couch_httpd:log_request(Req, Code),
-    Resp = MochiReq:respond({Code,
-        default_or_content_type(CType, Headers ++ couch_httpd:server_header()), Data}),
-    {ok, Resp}.
+    Headers1 = default_or_content_type(CType, Headers),
+    case Json of
+    nil ->
+        couch_httpd:send_response(Req, Code, Headers1, Data);
+    Json ->
+        couch_httpd:send_json(Req, Code, Headers1, Json)
+    end.
 
 parse_external_response({Response}) ->
     lists:foldl(fun({Key,Value}, Args) ->
@@ -143,7 +147,7 @@ parse_external_response({Response}) ->
                 Args#extern_resp_args{stop=true};
             {<<"json">>, Value} ->
                 Args#extern_resp_args{
-                    data=?JSON_ENCODE(Value),
+                    json=Value,
                     ctype="application/json"};
             {<<"body">>, Value} ->
                 Args#extern_resp_args{data=Value, ctype="text/html; charset=utf-8"};


Mime
View raw message