You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2015/06/29 23:46:52 UTC
[46/50] couch commit: updated refs/heads/COUCHDB-2734-header-date to
f3e022c
Don't use message queue for request handling
Using the message queue messes with fabric, so don't do that.
Reverts f11da939a8ddaa87244f9c1f53dd67a2ef70699c
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/15dc622f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/15dc622f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/15dc622f
Branch: refs/heads/COUCHDB-2734-header-date
Commit: 15dc622fd8fd7c59890bc7d057f332e0aea46a77
Parents: 432c949
Author: Robert Newson <rn...@apache.org>
Authored: Sun May 18 16:25:33 2014 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sun May 18 16:27:43 2014 +0100
----------------------------------------------------------------------
src/mochiweb_http.erl | 40 ++++++++++++++++------------------------
1 file changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/15dc622f/src/mochiweb_http.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl
index 38d51d4..16a9480 100644
--- a/src/mochiweb_http.erl
+++ b/src/mochiweb_http.erl
@@ -57,26 +57,22 @@ loop(Socket, Body) ->
request(Socket, Body).
request(Socket, Body) ->
- ok = mochiweb_socket:setopts(Socket, [{active, once}]),
- receive
- {Protocol, _, {http_request, Method, Path, Version}} when Protocol == http orelse Protocol == ssl ->
+ case mochiweb_socket:recv(Socket, 0, ?REQUEST_RECV_TIMEOUT) of
+ {ok, {http_request, Method, Path, Version}} ->
ok = mochiweb_socket:setopts(Socket, [{packet, httph}]),
headers(Socket, {Method, Path, Version}, [], Body, 0);
- {Protocol, _, {http_error, "\r\n"}} when Protocol == http orelse Protocol == ssl ->
+ {error, {http_error, "\r\n"}} ->
request(Socket, Body);
- {Protocol, _, {http_error, "\n"}} when Protocol == http orelse Protocol == ssl ->
+ {error, {http_error, "\n"}} ->
request(Socket, Body);
- {tcp_closed, _} ->
+ {error, closed} ->
mochiweb_socket:close(Socket),
exit(normal);
- {ssl_closed, _} ->
+ {error, timeout} ->
mochiweb_socket:close(Socket),
exit(normal);
Other ->
handle_invalid_msg_request(Other, Socket)
- after ?REQUEST_RECV_TIMEOUT ->
- mochiweb_socket:close(Socket),
- exit(normal)
end.
reentry(Body) ->
@@ -89,23 +85,21 @@ headers(Socket, Request, Headers, _Body, ?MAX_HEADERS) ->
ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
handle_invalid_request(Socket, Request, Headers);
headers(Socket, Request, Headers, Body, HeaderCount) ->
- ok = mochiweb_socket:setopts(Socket, [{active, once}]),
- receive
- {Protocol, _, http_eoh} when Protocol == http orelse Protocol == ssl ->
- Req = new_request(Socket, Request, Headers),
+ case mochiweb_socket:recv(Socket, 0, ?HEADERS_RECV_TIMEOUT) of
+ {ok, http_eoh} ->
+ mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ Req = mochiweb:new_request({Socket, Request,
+ lists:reverse(Headers)}),
call_body(Body, Req),
?MODULE:after_response(Body, Req);
- {Protocol, _, {http_header, _, Name, _, Value}} when Protocol == http orelse Protocol == ssl ->
+ {ok, {http_header, _, Name, _, Value}} ->
headers(Socket, Request, [{Name, Value} | Headers], Body,
1 + HeaderCount);
- {tcp_closed, _} ->
+ {error, closed} ->
mochiweb_socket:close(Socket),
exit(normal);
Other ->
handle_invalid_msg_request(Other, Socket, Request, Headers)
- after ?HEADERS_RECV_TIMEOUT ->
- mochiweb_socket:close(Socket),
- exit(normal)
end.
call_body({M, F, A}, Req) ->
@@ -132,15 +126,13 @@ handle_invalid_msg_request(Msg, Socket, Request, RevHeaders) ->
-spec handle_invalid_request(term(), term(), term()) -> no_return().
handle_invalid_request(Socket, Request, RevHeaders) ->
- Req = new_request(Socket, Request, RevHeaders),
+ mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ Req = mochiweb:new_request({Socket, Request,
+ lists:reverse(RevHeaders)}),
Req:respond({400, [], []}),
mochiweb_socket:close(Socket),
exit(normal).
-new_request(Socket, Request, RevHeaders) ->
- ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
- mochiweb:new_request({Socket, Request, lists:reverse(RevHeaders)}).
-
after_response(Body, Req) ->
Socket = Req:get(socket),
case Req:should_close() of