| 1 |
%% Copyright (c) Loïc Hoguin <[email protected]> |
| 2 |
%% |
| 3 |
%% Permission to use, copy, modify, and/or distribute this software for any |
| 4 |
%% purpose with or without fee is hereby granted, provided that the above |
| 5 |
%% copyright notice and this permission notice appear in all copies. |
| 6 |
%% |
| 7 |
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 |
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 |
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 |
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 |
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 |
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 13 |
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 |
|
| 15 |
-module(rfc6585_SUITE). |
| 16 |
-compile(export_all). |
| 17 |
-compile(nowarn_export_all). |
| 18 |
|
| 19 |
-import(ct_helper, [config/2]). |
| 20 |
-import(ct_helper, [doc/1]). |
| 21 |
-import(cowboy_test, [gun_open/1]). |
| 22 |
|
| 23 |
all() -> |
| 24 |
cowboy_test:common_all(). |
| 25 |
|
| 26 |
groups() -> |
| 27 |
cowboy_test:common_groups(ct_helper:all(?MODULE)). |
| 28 |
|
| 29 |
init_per_group(Name, Config) -> |
| 30 |
cowboy_test:init_common_groups(Name, Config, ?MODULE). |
| 31 |
|
| 32 |
end_per_group(Name, _) -> |
| 33 |
cowboy_test:stop_group(Name). |
| 34 |
|
| 35 |
init_dispatch(_) -> |
| 36 |
cowboy_router:compile([{"[...]", [ |
| 37 |
{"/resp/:key[/:arg]", resp_h, []} |
| 38 |
]}]). |
| 39 |
|
| 40 |
status_code_428(Config) -> |
| 41 |
doc("The 428 Precondition Required status code can be sent. (RFC6585 3)"), |
| 42 |
ConnPid = gun_open(Config), |
| 43 |
Ref = gun:get(ConnPid, "/resp/reply2/428", [ |
| 44 |
{<<"accept-encoding">>, <<"gzip">>} |
| 45 |
]), |
| 46 |
{response, _, 428, _} = gun:await(ConnPid, Ref), |
| 47 |
ok. |
| 48 |
|
| 49 |
status_code_429(Config) -> |
| 50 |
doc("The 429 Too Many Requests status code can be sent. (RFC6585 4)"), |
| 51 |
ConnPid = gun_open(Config), |
| 52 |
Ref = gun:get(ConnPid, "/resp/reply2/429", [ |
| 53 |
{<<"accept-encoding">>, <<"gzip">>} |
| 54 |
]), |
| 55 |
{response, _, 429, _} = gun:await(ConnPid, Ref), |
| 56 |
ok. |
| 57 |
|
| 58 |
%% @todo |
| 59 |
% The (429) response MAY include a Retry-After header indicating how long |
| 60 |
% to wait before making a new request. (RFC6585 4) |
| 61 |
|
| 62 |
status_code_431(Config) -> |
| 63 |
doc("The 431 Request Header Fields Too Large status code can be sent. (RFC6585 5)"), |
| 64 |
ConnPid = gun_open(Config), |
| 65 |
Ref = gun:get(ConnPid, "/resp/reply2/431", [ |
| 66 |
{<<"accept-encoding">>, <<"gzip">>} |
| 67 |
]), |
| 68 |
{response, _, 431, _} = gun:await(ConnPid, Ref), |
| 69 |
ok. |
| 70 |
|
| 71 |
status_code_511(Config) -> |
| 72 |
doc("The 511 Network Authentication Required status code can be sent. (RFC6585 6)"), |
| 73 |
ConnPid = gun_open(Config), |
| 74 |
Ref = gun:get(ConnPid, "/resp/reply2/511", [ |
| 75 |
{<<"accept-encoding">>, <<"gzip">>} |
| 76 |
]), |
| 77 |
{response, _, 511, _} = gun:await(ConnPid, Ref), |
| 78 |
ok. |