mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
add allowd_methods tests
This commit is contained in:
parent
3df6822ade
commit
1288e68f31
2 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue