couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [24/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372
Date Tue, 01 Mar 2016 20:00:57 GMT
Exatract handle_response function


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

Branch: refs/heads/split_out_httpd_stack
Commit: e7647e3809c804389bf5c6883425676e9658a343
Parents: 79084ea
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Feb 26 10:33:22 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 1 08:35:08 2016 -0800

----------------------------------------------------------------------
 src/couch_httpd.erl | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/e7647e38/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index f863359..d43fe87 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -120,33 +120,24 @@
     resp=nil
 }).
 
-start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = add_headers(Req, Headers0),
-    Resp = MochiReq:start_response_length({Code, Headers1, Length}),
+start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
+    Resp = handle_response(Req, Code, Headers, Length, start_response_length),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
     end,
     {ok, Resp}.
 
-start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = add_headers(Req, Headers0),
-    Resp = MochiReq:start_response({Code, Headers1}),
+start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
+    Resp = handle_response(Req, Code, Headers, undefined, start_response),
     case MochiReq:get(method) of
         'HEAD' -> throw({http_head_abort, Resp});
         _ -> ok
     end,
     {ok, Resp}.
 
-start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = add_headers(Req, Headers0),
-    Resp = MochiReq:respond({Code, Headers1, chunked}),
+start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
+    Resp = handle_response(Req, Code, Headers, chunked, respond),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -208,17 +199,15 @@ start_delayed_json_response(Req, Code, Headers, FirstChunk) ->
         headers = Headers,
         first_chunk = FirstChunk}}.
 
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Body) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
+send_response(#httpd{}=Req, Code, Headers, Body) ->
+    Resp = handle_response(Req, Code, Headers, Body, respond),
     if Code >= 500 ->
         couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
     Code >= 400 ->
         couch_log:debug("httpd ~p error response:~n ~s", [Code, Body]);
     true -> ok
     end,
-    Headers1 = add_headers(Req, Headers0),
-    {ok, MochiReq:respond({Code, Headers1, Body})}.
+    {ok, Resp}.
 
 send_json(Req, Value) ->
     send_json(Req, 200, Value).
@@ -952,6 +941,17 @@ validate_callback([Char | Rest]) ->
     end,
     validate_callback(Rest).
 
+handle_response(Req, Code, Headers0, Args, Type) ->
+    log_request(Req, Code),
+    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
+    Headers1 = add_headers(Req, Headers0),
+    respond_(Req, Code, Headers1, Args, Type).
+
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
+    MochiReq:start_response({Code, Headers});
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
+    MochiReq:Type({Code, Headers, Args}).
+
 %%%%%%%% module tests below %%%%%%%%
 
 -ifdef(TEST).


Mime
View raw message