couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [1/6] couch commit: updated refs/heads/master to 171b751
Date Tue, 15 Mar 2016 17:34:34 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 9d28c5715 -> 171b7513a


Pass unencoded JsonObj to before_request

It is much easier to write epi plugins if the object
it receives is not encoded yet.
So we pass unencoded JSON object to chttpd_plugin:before_response

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 3be679625e1054d897d6a905e895548ea7949b13
Parents: 9228302
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Mar 10 07:53:43 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 15 10:14:17 2016 -0700

----------------------------------------------------------------------
 src/couch_httpd.erl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3be67962/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index ebfa5c3..40f5c99 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -745,8 +745,7 @@ send_json(Req, Code, Value) ->
 send_json(Req, Code, Headers, Value) ->
     initialize_jsonp(Req),
     AllHeaders = maybe_add_default_headers(Req, Headers),
-    Body = [start_jsonp(), ?JSON_ENCODE(Value), end_jsonp(), $\n],
-    send_response(Req, Code, AllHeaders, Body).
+    send_response(Req, Code, AllHeaders, {json, Value}).
 
 start_json_response(Req, Code) ->
     start_json_response(Req, Code, []).
@@ -1121,12 +1120,19 @@ basic_headers_no_cors(Req, Headers) ->
         ++ couch_httpd_auth:cookie_auth_header(Req, Headers).
 
 handle_response(Req0, Code0, Headers0, Args0, Type) ->
-    {ok, {Req1, Code1, Headers1, Args1}} =
-        chttpd_plugin:before_response(Req0, Code0, Headers0, Args0),
+    {ok, {Req1, Code1, Headers1, Args1}} = before_response(Req0, Code0, Headers0, Args0),
     couch_stats:increment_counter([couchdb, httpd_status_codes, Code1]),
     log_request(Req0, Code1),
     respond_(Req1, Code1, Headers1, Args1, Type).
 
+before_response(Req0, Code0, Headers0, {json, JsonObj}) ->
+    {ok, {Req1, Code1, Headers1, Body1}} =
+        chttpd_plugin:before_response(Req0, Code0, Headers0, JsonObj),
+    Body2 = [start_jsonp(), ?JSON_ENCODE(Body1), end_jsonp(), $\n],
+    {ok, {Req1, Code1, Headers1, Body2}};
+before_response(Req0, Code0, Headers0, Args0) ->
+    chttpd_plugin:before_response(Req0, Code0, Headers0, Args0).
+
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
     MochiReq:start_response({Code, Headers});
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->


Mime
View raw message