diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl index 8efcfc5b..b50b1baa 100644 --- a/src/cowboy_rest.erl +++ b/src/cowboy_rest.erl @@ -340,8 +340,7 @@ allowed_methods(Req, State=#state{method=Method}) -> next(Req, State#state{allowed_methods=DefaultAllowedMethods}, fun malformed_request/2); no_call -> - method_not_allowed(Req, State, - [<<"HEAD">>, <<"GET">>, <<"OPTIONS">>]); + method_not_allowed(Req, State, DefaultAllowedMethods); {stop, Req2, State2} -> terminate(Req2, State2); {Switch, Req2, State2} when element(1, Switch) =:= switch_handler -> @@ -349,12 +348,14 @@ allowed_methods(Req, State=#state{method=Method}) -> {List, Req2, State2} -> case lists:member(Method, List) of true when Method =:= <<"OPTIONS">> -> - << ", ", Allow/binary >> = << << ", ", M/binary >> || M <- List >>, + Allow = stringify_allowed_methods(List), Req3 = cowboy_req:set_resp_header(<<"allow">>, Allow, Req2), next(Req3, State2#state{allowed_methods=List}, fun malformed_request/2); true -> - next(Req2, State2, fun malformed_request/2); + Allow = stringify_allowed_methods(List), + Req3 = cowboy_req:set_resp_header(<<"allow">>, Allow, Req2), + next(Req3, State2, fun malformed_request/2); false -> method_not_allowed(Req2, State2, List) end diff --git a/test/rest_handler_SUITE.erl b/test/rest_handler_SUITE.erl index d43b8f16..d8998e9a 100644 --- a/test/rest_handler_SUITE.erl +++ b/test/rest_handler_SUITE.erl @@ -472,7 +472,8 @@ delete_resource_missing(Config) -> Ref = gun:delete(ConnPid, "/delete_resource?missing", [ {<<"accept-encoding">>, <<"gzip">>} ]), - {response, _, 500, _} = gun:await(ConnPid, Ref), + {response, _, 500, Headers} = gun:await(ConnPid, Ref), + {_, <<"DELETE">>} = lists:keyfind(<<"allow">>, 1, Headers), ok. create_resource_created(Config) -> @@ -483,7 +484,8 @@ create_resource_created(Config) -> Ref = gun:post(ConnPid, "/create_resource?created", [ {<<"content-type">>, <<"application/text">>} ], <<"hello">>, #{}), - {response, _, 201, _} = gun:await(ConnPid, Ref), + {response, _, 201, Headers} = gun:await(ConnPid, Ref), + {_, <<"POST">>} = lists:keyfind(<<"allow">>, 1, Headers), ok. create_resource_see_other(Config) -> @@ -496,6 +498,7 @@ create_resource_see_other(Config) -> ], <<"hello">>, #{}), {response, _, 303, RespHeaders} = gun:await(ConnPid, Ref), {_, _} = lists:keyfind(<<"location">>, 1, RespHeaders), + {_, <<"POST">>} = lists:keyfind(<<"allow">>, 1, RespHeaders), ok. error_on_malformed_accept(Config) ->