summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2011-10-20 16:17:22 +0100
committerRobert Newson <rnewson@apache.org>2013-02-07 22:44:27 +0000
commit35739526745fe5069aafa51f35a1f3a470683f64 (patch)
tree8c55d4b8a10b2429f9189912dfda0dd02880126c
parent8848b5ddb065a84d6762c3ec59cbba2c704eda8d (diff)
downloadcouchdb-35739526745fe5069aafa51f35a1f3a470683f64.tar.gz
support JSONP in externals
COUCHDB-1313
-rw-r--r--src/couchdb/couch_db.hrl3
-rw-r--r--src/couchdb/couch_httpd_external.erl18
2 files changed, 13 insertions, 8 deletions
diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl
index 3b08de864..f79e5f773 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,
diff --git a/src/couchdb/couch_httpd_external.erl b/src/couchdb/couch_httpd_external.erl
index bfe77a329..2036d252e 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"};