mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
return allow header
This commit is contained in:
parent
5fe1be7007
commit
6b14cd64fc
2 changed files with 18 additions and 2 deletions
|
@ -328,7 +328,9 @@ uri_too_long(Req, State) ->
|
||||||
allowed_methods(Req, State=#state{method=Method}) ->
|
allowed_methods(Req, State=#state{method=Method}) ->
|
||||||
case call(Req, State, allowed_methods) of
|
case call(Req, State, allowed_methods) of
|
||||||
no_call when Method =:= <<"HEAD">>; Method =:= <<"GET">> ->
|
no_call when Method =:= <<"HEAD">>; Method =:= <<"GET">> ->
|
||||||
next(Req, State, fun malformed_request/2);
|
Allow = <<"HEAD, GET, OPTIONS">>,
|
||||||
|
Req2 = cowboy_req:set_resp_header(<<"allow">>, Allow, Req),
|
||||||
|
next(Req2, State, fun malformed_request/2);
|
||||||
no_call when Method =:= <<"OPTIONS">> ->
|
no_call when Method =:= <<"OPTIONS">> ->
|
||||||
next(Req, State#state{allowed_methods=
|
next(Req, State#state{allowed_methods=
|
||||||
[<<"HEAD">>, <<"GET">>, <<"OPTIONS">>]},
|
[<<"HEAD">>, <<"GET">>, <<"OPTIONS">>]},
|
||||||
|
@ -343,7 +345,9 @@ allowed_methods(Req, State=#state{method=Method}) ->
|
||||||
{List, Req2, State2} ->
|
{List, Req2, State2} ->
|
||||||
case lists:member(Method, List) of
|
case lists:member(Method, List) of
|
||||||
true when Method =:= <<"OPTIONS">> ->
|
true when Method =:= <<"OPTIONS">> ->
|
||||||
next(Req2, State2#state{allowed_methods=List},
|
<< ", ", Allow/binary >> = << << ", ", M/binary >> || M <- List >>,
|
||||||
|
Req3 = cowboy_req:set_resp_header(<<"allow">>, Allow, Req2),
|
||||||
|
next(Req3, State2#state{allowed_methods=List},
|
||||||
fun malformed_request/2);
|
fun malformed_request/2);
|
||||||
true ->
|
true ->
|
||||||
next(Req2, State2, fun malformed_request/2);
|
next(Req2, State2, fun malformed_request/2);
|
||||||
|
|
|
@ -778,6 +778,17 @@ last_modified_missing(Config) ->
|
||||||
false = lists:keyfind(<<"last-modified">>, 1, Headers),
|
false = lists:keyfind(<<"last-modified">>, 1, Headers),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
head_call(Config) ->
|
||||||
|
doc("A successful HEAD request to a simple handler results in "
|
||||||
|
"a 200 OK response with the allow header set. (RFC7231 4.3.7)"),
|
||||||
|
ConnPid = gun_open(Config),
|
||||||
|
Ref = gun:head(ConnPid, "/", [
|
||||||
|
{<<"accept-encoding">>, <<"gzip">>}
|
||||||
|
]),
|
||||||
|
{response, fin, 200, Headers} = gun:await(ConnPid, Ref),
|
||||||
|
{_, <<"HEAD, GET, OPTIONS">>} = lists:keyfind(<<"allow">>, 1, Headers),
|
||||||
|
ok.
|
||||||
|
|
||||||
options_missing(Config) ->
|
options_missing(Config) ->
|
||||||
doc("A successful OPTIONS request to a simple handler results in "
|
doc("A successful OPTIONS request to a simple handler results in "
|
||||||
"a 200 OK response with the allow header set. (RFC7231 4.3.7)"),
|
"a 200 OK response with the allow header set. (RFC7231 4.3.7)"),
|
||||||
|
@ -799,6 +810,7 @@ provide_callback(Config) ->
|
||||||
]),
|
]),
|
||||||
{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
|
{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
|
||||||
{_, <<"text/plain">>} = lists:keyfind(<<"content-type">>, 1, Headers),
|
{_, <<"text/plain">>} = lists:keyfind(<<"content-type">>, 1, Headers),
|
||||||
|
{_, <<"HEAD, GET, OPTIONS">>} = lists:keyfind(<<"allow">>, 1, Headers),
|
||||||
{ok, <<"This is REST!">>} = gun:await_body(ConnPid, Ref),
|
{ok, <<"This is REST!">>} = gun:await_body(ConnPid, Ref),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue