You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/11/24 21:16:21 UTC
[4/4] chttpd commit: updated refs/heads/master to 7dcf127
Get rid of confusing function
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/7dcf1279
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/7dcf1279
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/7dcf1279
Branch: refs/heads/master
Commit: 7dcf1279bcdb546b4b284bc8bcbd51843849b04a
Parents: 21abde5
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Nov 19 10:11:25 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Nov 19 10:11:25 2015 -0800
----------------------------------------------------------------------
src/chttpd.erl | 51 ++++++++++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7dcf1279/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 5459f9b..7e214a9 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -210,16 +210,24 @@ handle_request_int(MochiReq) ->
% suppress duplicate log
erlang:put(dont_log_request, true),
- Result0 = case before_request(HttpReq0) of
+ {HttpReq2, Response} = case before_request(HttpReq0) of
{ok, HttpReq1} ->
process_request(HttpReq1);
- {error, Response} ->
- {HttpReq0, Response}
+ {error, Response0} ->
+ {HttpReq0, Response0}
end,
- {HttpReq3, HttpResp0} = result(Result0, HttpReq0),
+ {Status, Code, Reason, Resp} = split_response(Response),
- case after_request(HttpReq3, HttpResp0) of
+ HttpResp = #httpd_resp{
+ code = Code,
+ status = Status,
+ response = Resp,
+ nonce = HttpReq2#httpd.nonce,
+ reason = Reason
+ },
+
+ case after_request(HttpReq2, HttpResp) of
#httpd_resp{status = ok, response = Resp} ->
{ok, Resp};
#httpd_resp{status = aborted, reason = Reason} ->
@@ -269,13 +277,13 @@ process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
fun chttpd_auth_request:authorize_request/1),
{AuthorizedReq, HandlerFun(AuthorizedReq)};
Response ->
- Response
+ {HttpReq, Response}
end;
Response ->
- Response
+ {HttpReq, Response}
end
catch Tag:Error ->
- catch_error(HttpReq, Tag, Error)
+ {HttpReq, catch_error(HttpReq, Tag, Error)}
end.
catch_error(_HttpReq, throw, {http_head_abort, Resp}) ->
@@ -314,27 +322,12 @@ catch_error(HttpReq, Tag, Error) ->
send_error(HttpReq, {Error, nil, Stack})
end.
-result({#httpd{} = Req, Result}, _) ->
- result(Result, Req);
-result(Result, #httpd{nonce = Nonce} = Req) ->
- {Status, Code, Reason} = case Result of
- {ok, #delayed_resp{resp=Resp}} ->
- {ok, Resp:get(code), undefined};
- {ok, Resp} ->
- {ok, Resp:get(code), undefined};
- {aborted, Resp, AbortReason} ->
- {aborted, Resp:get(code), AbortReason}
- end,
-
- HttpResp = #httpd_resp{
- code = Code,
- status = Status,
- response = Resp,
- nonce = Nonce,
- reason = Reason
- },
- {Req, HttpResp}.
-
+split_response({ok, #delayed_resp{resp=Resp}}) ->
+ {ok, Resp:get(code), undefined, Resp};
+split_response({ok, Resp}) ->
+ {ok, Resp:get(code), undefined, Resp};
+split_response({aborted, Resp, AbortReason}) ->
+ {aborted, Resp:get(code), AbortReason, Resp}.
update_stats(HttpReq, #httpd_resp{end_ts = undefined} = Res) ->
update_stats(HttpReq, Res#httpd_resp{end_ts = os:timestamp()});