diff options
author | Loïc Hoguin <[email protected]> | 2014-11-07 20:19:05 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-11-07 20:19:05 +0200 |
commit | 999dc5b7c1665fb620c14f6303610793313efe58 (patch) | |
tree | 8371be2957e20b40fa9b5b93c63e414510e93c2e /src | |
parent | 8cbd8c1882e33380875f2723cad258784ba3a360 (diff) | |
download | cowboy-999dc5b7c1665fb620c14f6303610793313efe58.tar.gz cowboy-999dc5b7c1665fb620c14f6303610793313efe58.tar.bz2 cowboy-999dc5b7c1665fb620c14f6303610793313efe58.zip |
Rename 'halt' to 'stop' for better consistency
Now everywhere in Cowboy when we want to stop something we return
a 'stop' tuple instead of one of the many choices depending on
context that we had before.
This particular change affects middlewares, sub protocols and
REST handlers which were using 'halt' to stop processing.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_middleware.erl | 2 | ||||
-rw-r--r-- | src/cowboy_protocol.erl | 4 | ||||
-rw-r--r-- | src/cowboy_rest.erl | 26 | ||||
-rw-r--r-- | src/cowboy_router.erl | 8 | ||||
-rw-r--r-- | src/cowboy_spdy.erl | 4 | ||||
-rw-r--r-- | src/cowboy_sub_protocol.erl | 2 |
6 files changed, 23 insertions, 23 deletions
diff --git a/src/cowboy_middleware.erl b/src/cowboy_middleware.erl index 7ff947e..7b0e760 100644 --- a/src/cowboy_middleware.erl +++ b/src/cowboy_middleware.erl @@ -20,5 +20,5 @@ -callback execute(Req, Env) -> {ok, Req, Env} | {suspend, module(), atom(), [any()]} - | {halt, Req} + | {stop, Req} when Req::cowboy_req:req(), Env::env(). diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index 2da3a15..e469bc7 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -431,7 +431,7 @@ execute(Req, State, Env, [Middleware|Tail]) -> {suspend, Module, Function, Args} -> erlang:hibernate(?MODULE, resume, [State, Env, Tail, Module, Function, Args]); - {halt, Req2} -> + {stop, Req2} -> next_request(Req2, State, ok) end. @@ -444,7 +444,7 @@ resume(State, Env, Tail, Module, Function, Args) -> {suspend, Module2, Function2, Args2} -> erlang:hibernate(?MODULE, resume, [State, Env, Tail, Module2, Function2, Args2]); - {halt, Req2} -> + {stop, Req2} -> next_request(Req2, State, ok) end. diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl index 306584a..dea47d8 100644 --- a/src/cowboy_rest.erl +++ b/src/cowboy_rest.erl @@ -84,7 +84,7 @@ known_methods(Req, State=#state{method=Method}) -> next(Req, State, fun uri_too_long/2); no_call -> next(Req, State, 501); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {List, Req2, HandlerState} -> State2 = State#state{handler_state=HandlerState}, @@ -109,7 +109,7 @@ allowed_methods(Req, State=#state{method=Method}) -> no_call -> method_not_allowed(Req, State, [<<"HEAD">>, <<"GET">>, <<"OPTIONS">>]); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {List, Req2, HandlerState} -> State2 = State#state{handler_state=HandlerState}, @@ -140,7 +140,7 @@ is_authorized(Req, State) -> case call(Req, State, is_authorized) of no_call -> forbidden(Req, State); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {true, Req2, HandlerState} -> forbidden(Req2, State#state{handler_state=HandlerState}); @@ -172,7 +172,7 @@ options(Req, State=#state{allowed_methods=Methods, method= <<"OPTIONS">>}) -> = << << ", ", M/binary >> || M <- Methods >>, Req2 = cowboy_req:set_resp_header(<<"allow">>, Allow, Req), respond(Req2, State, 200); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {ok, Req2, HandlerState} -> respond(Req2, State#state{handler_state=HandlerState}, 200) @@ -211,7 +211,7 @@ content_types_provided(Req, State) -> catch _:_ -> respond(Req, State2, 400) end; - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {[], Req2, HandlerState} -> not_acceptable(Req2, State#state{handler_state=HandlerState}); @@ -313,7 +313,7 @@ languages_provided(Req, State) -> case call(Req, State, languages_provided) of no_call -> charsets_provided(Req, State); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {[], Req2, HandlerState} -> not_acceptable(Req2, State#state{handler_state=HandlerState}); @@ -373,7 +373,7 @@ charsets_provided(Req, State) -> case call(Req, State, charsets_provided) of no_call -> set_content_type(Req, State); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {[], Req2, HandlerState} -> not_acceptable(Req2, State#state{handler_state=HandlerState}); @@ -645,7 +645,7 @@ moved_permanently(Req, State, OnFalse) -> respond(Req3, State#state{handler_state=HandlerState}, 301); {false, Req2, HandlerState} -> OnFalse(Req2, State#state{handler_state=HandlerState}); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); no_call -> OnFalse(Req, State) @@ -666,7 +666,7 @@ moved_temporarily(Req, State) -> respond(Req3, State#state{handler_state=HandlerState}, 307); {false, Req2, HandlerState} -> is_post_to_missing_resource(Req2, State#state{handler_state=HandlerState}, 410); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); no_call -> is_post_to_missing_resource(Req, State, 410) @@ -716,7 +716,7 @@ accept_resource(Req, State) -> case call(Req, State, content_types_accepted) of no_call -> respond(Req, State, 415); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {CTA, Req2, HandlerState} -> CTA2 = [normalize_content_types(P) || P <- CTA], @@ -751,7 +751,7 @@ choose_content_type(Req, State, ContentType, [_Any|Tail]) -> process_content_type(Req, State=#state{method=Method, exists=Exists}, Fun) -> try case call(Req, State, Fun) of - {halt, Req2, HandlerState2} -> + {stop, Req2, HandlerState2} -> terminate(Req2, State#state{handler_state=HandlerState2}); {true, Req2, HandlerState2} when Exists -> State2 = State#state{handler_state=HandlerState2}, @@ -832,7 +832,7 @@ set_resp_body_expires(Req, State) -> %% it to the response. set_resp_body(Req, State=#state{content_type_a={_, Callback}}) -> try case call(Req, State, Callback) of - {halt, Req2, HandlerState2} -> + {stop, Req2, HandlerState2} -> terminate(Req2, State#state{handler_state=HandlerState2}); {Body, Req2, HandlerState2} -> State2 = State#state{handler_state=HandlerState2}, @@ -936,7 +936,7 @@ expect(Req, State, Callback, Expected, OnTrue, OnFalse) -> case call(Req, State, Callback) of no_call -> next(Req, State, OnTrue); - {halt, Req2, HandlerState} -> + {stop, Req2, HandlerState} -> terminate(Req2, State#state{handler_state=HandlerState}); {Expected, Req2, HandlerState} -> next(Req2, State#state{handler_state=HandlerState}, OnTrue); diff --git a/src/cowboy_router.erl b/src/cowboy_router.erl index 2d1924d..f3fde32 100644 --- a/src/cowboy_router.erl +++ b/src/cowboy_router.erl @@ -157,7 +157,7 @@ compile_brackets_split(<< C, Rest/bits >>, Acc, N) -> compile_brackets_split(Rest, << Acc/binary, C >>, N). -spec execute(Req, Env) - -> {ok, Req, Env} | {halt, Req} + -> {ok, Req, Env} | {stop, Req} when Req::cowboy_req:req(), Env::cowboy_middleware:env(). execute(Req, Env) -> {_, Dispatch} = lists:keyfind(dispatch, 1, Env), @@ -168,11 +168,11 @@ execute(Req, Env) -> Req2 = cowboy_req:set_bindings(HostInfo, PathInfo, Bindings, Req), {ok, Req2, [{handler, Handler}, {handler_opts, HandlerOpts}|Env]}; {error, notfound, host} -> - {halt, cowboy_req:reply(400, Req)}; + {stop, cowboy_req:reply(400, Req)}; {error, badrequest, path} -> - {halt, cowboy_req:reply(400, Req)}; + {stop, cowboy_req:reply(400, Req)}; {error, notfound, path} -> - {halt, cowboy_req:reply(404, Req)} + {stop, cowboy_req:reply(404, Req)} end. %% Internal. diff --git a/src/cowboy_spdy.erl b/src/cowboy_spdy.erl index 4d83ff6..91c4f4a 100644 --- a/src/cowboy_spdy.erl +++ b/src/cowboy_spdy.erl @@ -406,7 +406,7 @@ execute(Req, Env, [Middleware|Tail]) -> {suspend, Module, Function, Args} -> erlang:hibernate(?MODULE, resume, [Env, Tail, Module, Function, Args]); - {halt, Req2} -> + {stop, Req2} -> cowboy_req:ensure_response(Req2, 204) end. @@ -419,7 +419,7 @@ resume(Env, Tail, Module, Function, Args) -> {suspend, Module2, Function2, Args2} -> erlang:hibernate(?MODULE, resume, [Env, Tail, Module2, Function2, Args2]); - {halt, Req2} -> + {stop, Req2} -> cowboy_req:ensure_response(Req2, 204) end. diff --git a/src/cowboy_sub_protocol.erl b/src/cowboy_sub_protocol.erl index f177263..b198a18 100644 --- a/src/cowboy_sub_protocol.erl +++ b/src/cowboy_sub_protocol.erl @@ -16,5 +16,5 @@ -module(cowboy_sub_protocol). -callback upgrade(Req, Env, module(), any(), timeout(), run | hibernate) - -> {ok, Req, Env} | {suspend, module(), atom(), [any()]} | {halt, Req} + -> {ok, Req, Env} | {suspend, module(), atom(), [any()]} | {stop, Req} when Req::cowboy_req:req(), Env::cowboy_middleware:env(). |