Permalink
Browse files

Fix a bug preventing 'onresponse' from being called on errors

  • Loading branch information...
1 parent ca9278b commit cc6c4e39de74f60747178a3e4bff8fdd65b70777 Loïc Hoguin committed May 21, 2012
Showing with 12 additions and 2 deletions.
  1. +3 −2 src/cowboy_http_protocol.erl
  2. +9 −0 test/http_SUITE.erl
@@ -438,12 +438,13 @@ ensure_response(#http_req{socket=Socket, transport=Transport,
%% Only send an error reply if there is no resp_sent message.
-spec error_terminate(cowboy_http:status(), #state{}) -> ok.
-error_terminate(Code, State=#state{socket=Socket, transport=Transport}) ->
+error_terminate(Code, State=#state{socket=Socket, transport=Transport,
+ onresponse=OnResponse}) ->
receive
{cowboy_http_req, resp_sent} -> ok
after 0 ->
_ = cowboy_http_req:reply(Code, #http_req{
- socket=Socket, transport=Transport,
+ socket=Socket, transport=Transport, onresponse=OnResponse,
connection=close, pid=self(), resp_state=waiting}),
ok
end,
View
@@ -45,6 +45,7 @@
-export([nc_zero/1]).
-export([onrequest/1]).
-export([onrequest_reply/1]).
+-export([onresponse_crash/1]).
-export([onresponse_reply/1]).
-export([pipeline/1]).
-export([rest_keepalive/1]).
@@ -116,6 +117,7 @@ groups() ->
onrequest_reply
]},
{onresponse, [], [
+ onresponse_crash,
onresponse_reply
]}
].
@@ -604,6 +606,13 @@ onrequest_hook(Req) ->
Req3
end.
+onresponse_crash(Config) ->
+ Client = ?config(client, Config),
+ {ok, Client2} = cowboy_client:request(<<"GET">>,
+ build_url("/handler_errors?case=init_before_reply", Config), Client),
+ {ok, 777, Headers, Client3} = cowboy_client:response(Client2),
+ {<<"x-hook">>, <<"onresponse">>} = lists:keyfind(<<"x-hook">>, 1, Headers).
+
onresponse_reply(Config) ->
Client = ?config(client, Config),
{ok, Client2} = cowboy_client:request(<<"GET">>,

0 comments on commit cc6c4e3

Please sign in to comment.