diff --git a/doc/src/guide/middlewares.ezdoc b/doc/src/guide/middlewares.ezdoc index 0c142f9d..35e9ea9e 100644 --- a/doc/src/guide/middlewares.ezdoc +++ b/doc/src/guide/middlewares.ezdoc @@ -23,7 +23,7 @@ Middlewares can return one of four different values: * `{ok, Req, Env}` to continue the request processing * `{suspend, Module, Function, Args}` to hibernate -* `{halt, Req}` to stop processing and move on to the next request +* `{stop, Req}` to stop processing and move on to the next request Of note is that when hibernating, processing will resume on the given MFA, discarding all previous stacktrace. Make sure you keep the `Req` diff --git a/doc/src/guide/rest_handlers.ezdoc b/doc/src/guide/rest_handlers.ezdoc index 1868f0a7..e09790a8 100644 --- a/doc/src/guide/rest_handlers.ezdoc +++ b/doc/src/guide/rest_handlers.ezdoc @@ -41,7 +41,7 @@ you need. All callbacks take two arguments, the Req object and the State, and return a three-element tuple of the form `{Value, Req, State}`. -All callbacks can also return `{halt, Req, State}` to stop execution +All callbacks can also return `{stop, Req, State}` to stop execution of the request. The following table summarizes the callbacks and their default values. diff --git a/doc/src/manual/cowboy_middleware.ezdoc b/doc/src/manual/cowboy_middleware.ezdoc index 2275d35e..dacaf6c8 100644 --- a/doc/src/manual/cowboy_middleware.ezdoc +++ b/doc/src/manual/cowboy_middleware.ezdoc @@ -21,7 +21,7 @@ optionally with its contents modified. : execute(Req, Env) -> {ok, Req, Env} | {suspend, Module, Function, Args} - | {halt, Req} + | {stop, Req} Types: @@ -41,7 +41,7 @@ The `suspend` return value will hibernate the process until an Erlang message is received. Note that when resuming, any previous stacktrace information will be gone. -The `halt` return value stops Cowboy from doing any further +The `stop` return value stops Cowboy from doing any further processing of the request, even if there are middlewares that haven't been executed yet. The connection may be left open to receive more requests from the client. diff --git a/doc/src/manual/cowboy_rest.ezdoc b/doc/src/manual/cowboy_rest.ezdoc index f9e938a1..eef622a9 100644 --- a/doc/src/manual/cowboy_rest.ezdoc +++ b/doc/src/manual/cowboy_rest.ezdoc @@ -58,7 +58,7 @@ stacktrace of the process when the crash occurred. :: Callbacks -: Callback(Req, State) -> {Value, Req, State} | {halt, Req, State} +: Callback(Req, State) -> {Value, Req, State} | {stop, Req, State} Types: @@ -72,7 +72,7 @@ on the `Value` type, the default value if the callback is not defined, and more general information on when the callback is called and what its intended use is. -The `halt` tuple can be returned to stop REST processing. +The `stop` tuple can be returned to stop REST processing. It is up to the resource code to send a reply before that, otherwise a `204 No Content` will be sent. diff --git a/doc/src/manual/cowboy_sub_protocol.ezdoc b/doc/src/manual/cowboy_sub_protocol.ezdoc index 4ad25f3d..ee57beba 100644 --- a/doc/src/manual/cowboy_sub_protocol.ezdoc +++ b/doc/src/manual/cowboy_sub_protocol.ezdoc @@ -8,8 +8,7 @@ by modules that implement a protocol on top of HTTP. : upgrade(Req, Env, Handler, Opts) -> {ok, Req, Env} | {suspend, Module, Function, Args} - | {halt, Req} - | {error, StatusCode, Req} + | {stop, Req} Types: diff --git a/src/cowboy_middleware.erl b/src/cowboy_middleware.erl index 7ff947e9..7b0e7605 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 2da3a153..e469bc72 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 306584a7..dea47d8e 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 2d1924df..f3fde322 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 4d83ff62..91c4f4a3 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 f177263e..b198a184 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(). diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index bd0f2477..1b819ae1 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -706,7 +706,7 @@ rest_patch(Config) -> Tests = [ {204, [{<<"content-type">>, <<"text/plain">>}], <<"whatever">>}, {400, [{<<"content-type">>, <<"text/plain">>}], <<"false">>}, - {400, [{<<"content-type">>, <<"text/plain">>}], <<"halt">>}, + {400, [{<<"content-type">>, <<"text/plain">>}], <<"stop">>}, {415, [{<<"content-type">>, <<"application/json">>}], <<"bad_content_type">>} ], ConnPid = gun_open(Config), diff --git a/test/http_SUITE_data/rest_patch_resource.erl b/test/http_SUITE_data/rest_patch_resource.erl index 03f780f2..c1244e7b 100644 --- a/test/http_SUITE_data/rest_patch_resource.erl +++ b/test/http_SUITE_data/rest_patch_resource.erl @@ -29,8 +29,8 @@ content_types_accepted(Req, State) -> patch_text_plain(Req, State) -> case cowboy_req:body(Req) of - {ok, <<"halt">>, Req0} -> - {halt, cowboy_req:reply(400, Req0), State}; + {ok, <<"stop">>, Req0} -> + {stop, cowboy_req:reply(400, Req0), State}; {ok, <<"false">>, Req0} -> {false, Req0, State}; {ok, _Body, Req0} ->