rfc6585_SUITE.erl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. %% Copyright (c) 2018, Loïc Hoguin <essen@ninenines.eu>
  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. -module(rfc6585_SUITE).
  15. -compile(export_all).
  16. -compile(nowarn_export_all).
  17. -import(ct_helper, [config/2]).
  18. -import(ct_helper, [doc/1]).
  19. -import(cowboy_test, [gun_open/1]).
  20. all() ->
  21. cowboy_test:common_all().
  22. groups() ->
  23. cowboy_test:common_groups(ct_helper:all(?MODULE)).
  24. init_per_group(Name, Config) ->
  25. cowboy_test:init_common_groups(Name, Config, ?MODULE).
  26. end_per_group(Name, _) ->
  27. cowboy:stop_listener(Name).
  28. init_dispatch(_) ->
  29. cowboy_router:compile([{"[...]", [
  30. {"/resp/:key[/:arg]", resp_h, []}
  31. ]}]).
  32. status_code_428(Config) ->
  33. doc("The 428 Precondition Required status code can be sent. (RFC6585 3)"),
  34. ConnPid = gun_open(Config),
  35. Ref = gun:get(ConnPid, "/resp/reply2/428", [
  36. {<<"accept-encoding">>, <<"gzip">>}
  37. ]),
  38. {response, _, 428, _} = gun:await(ConnPid, Ref),
  39. ok.
  40. status_code_429(Config) ->
  41. doc("The 429 Too Many Requests status code can be sent. (RFC6585 4)"),
  42. ConnPid = gun_open(Config),
  43. Ref = gun:get(ConnPid, "/resp/reply2/429", [
  44. {<<"accept-encoding">>, <<"gzip">>}
  45. ]),
  46. {response, _, 429, _} = gun:await(ConnPid, Ref),
  47. ok.
  48. %% @todo
  49. % The (429) response MAY include a Retry-After header indicating how long
  50. % to wait before making a new request. (RFC6585 4)
  51. status_code_431(Config) ->
  52. doc("The 431 Request Header Fields Too Large status code can be sent. (RFC6585 5)"),
  53. ConnPid = gun_open(Config),
  54. Ref = gun:get(ConnPid, "/resp/reply2/431", [
  55. {<<"accept-encoding">>, <<"gzip">>}
  56. ]),
  57. {response, _, 431, _} = gun:await(ConnPid, Ref),
  58. ok.
  59. status_code_511(Config) ->
  60. doc("The 511 Network Authentication Required status code can be sent. (RFC6585 6)"),
  61. ConnPid = gun_open(Config),
  62. Ref = gun:get(ConnPid, "/resp/reply2/511", [
  63. {<<"accept-encoding">>, <<"gzip">>}
  64. ]),
  65. {response, _, 511, _} = gun:await(ConnPid, Ref),
  66. ok.