0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00

Better handle socket closing with loop handlers

We now read from the socket to be able to detect errors or TCP close
events, and buffer the data if any. Once the data receive goes over
a certain limit, which defaults to 5000 bytes, we simply close the
connection with an {error, overflow} reason.
This commit is contained in:
Loïc Hoguin 2013-02-11 09:03:13 +01:00
parent 65ed13d2da
commit 40b8d0befc
4 changed files with 84 additions and 17 deletions

View file

@ -104,6 +104,7 @@
-export([ensure_response/2]).
%% Private setter/getter API.
-export([append_buffer/2]).
-export([get/2]).
-export([set/2]).
-export([set_bindings/4]).
@ -1065,6 +1066,11 @@ ensure_response(#http_req{socket=Socket, transport=Transport,
%% Private setter/getter API.
%% @private
-spec append_buffer(binary(), Req) -> Req when Req::req().
append_buffer(Suffix, Req=#http_req{buffer=Buffer}) ->
Req#http_req{buffer= << Buffer/binary, Suffix/binary >>}.
%% @private
-spec get(atom(), req()) -> any(); ([atom()], req()) -> any().
get(List, Req) when is_list(List) ->