Browse Source

Move the error response code into a separate function.

Loïc Hoguin 14 years ago
parent
commit
a1e56a2fba
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/cowboy_http_protocol.erl

+ 9 - 3
src/cowboy_http_protocol.erl

@@ -165,11 +165,17 @@ handler_terminate(HandlerState, Req, State=#state{handler={Handler, _Opts}}) ->
 	end.
 	end.
 
 
 -spec error_terminate(Code::http_status(), State::#state{}) -> ok.
 -spec error_terminate(Code::http_status(), State::#state{}) -> ok.
-error_terminate(Code, State=#state{socket=Socket, transport=Transport}) ->
-	cowboy_http_req:reply(Code, [], [], #http_req{socket=Socket,
-		transport=Transport, connection=close}),
+error_terminate(Code, State) ->
+	error_response(Code, State#state{connection=close}),
 	terminate(State).
 	terminate(State).
 
 
+-spec error_response(Code::http_status(), State::#state{}) -> ok.
+error_response(Code, #state{socket=Socket,
+		transport=Transport, connection=Connection}) ->
+	cowboy_http_req:reply(Code, [], [], #http_req{
+		socket=Socket, transport=Transport,
+		connection=Connection, resp_state=waiting}).
+
 -spec terminate(State::#state{}) -> ok.
 -spec terminate(State::#state{}) -> ok.
 terminate(#state{socket=Socket, transport=Transport}) ->
 terminate(#state{socket=Socket, transport=Transport}) ->
 	Transport:close(Socket),
 	Transport:close(Socket),