Extract handle_response function

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 34bd2946074dd1ecd6b1952d315e000b1c85007c
Parents: b32f2b6
Author: ILYA Khlopotov <iil...@ca.ibm.com>
Authored: Tue Mar 8 08:57:55 2016 -0800
Committer: ILYA Khlopotov <iil...@ca.ibm.com>
Committed: Tue Mar 15 10:43:56 2016 -0700

----------------------------------------------------------------------
 src/chttpd.erl | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/34bd2946/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 673465e..f653a3d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -656,9 +656,8 @@ 
verify_is_server_admin(#httpd{user_ctx=#user_ctx{roles=Roles}}) ->
     end.
 
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) 
->
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
     Headers1 = basic_headers(Req, Headers0),
-    Resp = MochiReq:start_response_length({Code, Headers1, Length}),
+    Resp = handle_response(Req, Code, Headers1, Length, start_response_length),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -670,9 +669,8 @@ send(Resp, Data) ->
     {ok, Resp}.
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
     Headers1 = basic_headers(Req, Headers0),
-    Resp = MochiReq:respond({Code, Headers1, chunked}),
+    Resp = handle_response(Req, Code, Headers1, chunked, respond),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -1067,3 +1065,12 @@ basic_headers(Req, Headers0) ->
         ++ server_header()
         ++ couch_httpd_auth:cookie_auth_header(Req, Headers0),
     chttpd_cors:headers(Req, Headers).
+
+handle_response(Req, Code, Headers, Args, Type) ->
+    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
+    respond_(Req, Code, Headers, 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}).

Reply via email to