rfc7231_SUITE.erl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. %% Copyright (c) 2017, 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(rfc7231_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. {"*", asterisk_h, []},
  31. {"/", hello_h, []},
  32. {"/echo/:key", echo_h, []},
  33. {"/resp/:key[/:arg]", resp_h, []}
  34. ]}]).
  35. %% @todo The documentation should list what methods, headers and status codes
  36. %% are handled automatically so users can know what befalls to them to implement.
  37. %% Methods.
  38. method_get(Config) ->
  39. doc("The GET method is accepted. (RFC7231 4.3.1)"),
  40. ConnPid = gun_open(Config),
  41. Ref = gun:get(ConnPid, "/", [
  42. {<<"accept-encoding">>, <<"gzip">>}
  43. ]),
  44. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  45. {ok, <<"Hello world!">>} = gun:await_body(ConnPid, Ref),
  46. ok.
  47. method_head(Config) ->
  48. doc("The HEAD method is accepted. (RFC7231 4.3.2)"),
  49. ConnPid = gun_open(Config),
  50. Ref = gun:head(ConnPid, "/", [
  51. {<<"accept-encoding">>, <<"gzip">>}
  52. ]),
  53. {response, fin, 200, _} = gun:await(ConnPid, Ref),
  54. ok.
  55. method_head_same_resp_headers_as_get(Config) ->
  56. doc("Responses to HEAD should return the same headers as GET. (RFC7231 4.3.2)"),
  57. ConnPid = gun_open(Config),
  58. Ref1 = gun:get(ConnPid, "/", [
  59. {<<"accept-encoding">>, <<"gzip">>}
  60. ]),
  61. {response, nofin, 200, Headers1} = gun:await(ConnPid, Ref1),
  62. {ok, <<"Hello world!">>} = gun:await_body(ConnPid, Ref1),
  63. Ref2 = gun:head(ConnPid, "/", [
  64. {<<"accept-encoding">>, <<"gzip">>}
  65. ]),
  66. {response, fin, 200, Headers2} = gun:await(ConnPid, Ref2),
  67. %% We remove the date header since the date might have changed between requests.
  68. Headers = lists:keydelete(<<"date">>, 1, Headers1),
  69. Headers = lists:keydelete(<<"date">>, 1, Headers2),
  70. ok.
  71. method_head_same_resp_headers_as_get_stream_reply(Config) ->
  72. doc("Responses to HEAD should return the same headers as GET. (RFC7231 4.3.2)"),
  73. ConnPid = gun_open(Config),
  74. Ref1 = gun:get(ConnPid, "/resp/stream_reply2/200", [
  75. {<<"accept-encoding">>, <<"gzip">>}
  76. ]),
  77. {response, nofin, 200, Headers1} = gun:await(ConnPid, Ref1),
  78. {ok, _} = gun:await_body(ConnPid, Ref1),
  79. Ref2 = gun:head(ConnPid, "/resp/stream_reply2/200", [
  80. {<<"accept-encoding">>, <<"gzip">>}
  81. ]),
  82. {response, fin, 200, Headers2} = gun:await(ConnPid, Ref2),
  83. %% We remove the date header since the date might have changed between requests.
  84. Headers = lists:keydelete(<<"date">>, 1, Headers1),
  85. Headers = lists:keydelete(<<"date">>, 1, Headers2),
  86. ok.
  87. method_post(Config) ->
  88. doc("The POST method is accepted. (RFC7231 4.3.3)"),
  89. ConnPid = gun_open(Config),
  90. Ref = gun:post(ConnPid, "/echo/read_body", [
  91. {<<"accept-encoding">>, <<"gzip">>},
  92. {<<"content-type">>, <<"application/x-www-form-urlencoded">>}
  93. ], <<"hello=world">>),
  94. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  95. {ok, <<"hello=world">>} = gun:await_body(ConnPid, Ref),
  96. ok.
  97. method_put(Config) ->
  98. doc("The PUT method is accepted. (RFC7231 4.3.4)"),
  99. ConnPid = gun_open(Config),
  100. Ref = gun:put(ConnPid, "/echo/read_body", [
  101. {<<"accept-encoding">>, <<"gzip">>},
  102. {<<"content-type">>, <<"application/x-www-form-urlencoded">>}
  103. ], <<"hello=world">>),
  104. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  105. {ok, <<"hello=world">>} = gun:await_body(ConnPid, Ref),
  106. ok.
  107. method_delete(Config) ->
  108. doc("The DELETE method is accepted. (RFC7231 4.3.5)"),
  109. ConnPid = gun_open(Config),
  110. Ref = gun:delete(ConnPid, "/echo/method", [
  111. {<<"accept-encoding">>, <<"gzip">>}
  112. ]),
  113. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  114. {ok, <<"DELETE">>} = gun:await_body(ConnPid, Ref),
  115. ok.
  116. method_connect(Config) ->
  117. doc("The CONNECT method is currently not implemented. (RFC7231 4.3.6)"),
  118. ConnPid = gun_open(Config),
  119. Ref = gun:request(ConnPid, <<"CONNECT">>, "localhost:8080", [
  120. {<<"accept-encoding">>, <<"gzip">>}
  121. ]),
  122. {response, fin, 501, _} = gun:await(ConnPid, Ref),
  123. ok.
  124. method_options(Config) ->
  125. doc("The OPTIONS method is accepted. (RFC7231 4.3.7)"),
  126. ConnPid = gun_open(Config),
  127. Ref = gun:options(ConnPid, "/echo/method", [
  128. {<<"accept-encoding">>, <<"gzip">>}
  129. ]),
  130. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  131. {ok, <<"OPTIONS">>} = gun:await_body(ConnPid, Ref),
  132. ok.
  133. method_options_asterisk(Config) ->
  134. doc("The OPTIONS method is accepted with an asterisk. (RFC7231 4.3.7)"),
  135. ConnPid = gun_open(Config),
  136. Ref = gun:options(ConnPid, "*", [
  137. {<<"accept-encoding">>, <<"gzip">>},
  138. {<<"x-echo">>, <<"method">>}
  139. ]),
  140. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  141. {ok, <<"OPTIONS">>} = gun:await_body(ConnPid, Ref),
  142. ok.
  143. method_options_content_length_0(Config) ->
  144. doc("The OPTIONS method must set the content-length header "
  145. "to 0 when no body is returned. (RFC7231 4.3.7)"),
  146. ConnPid = gun_open(Config),
  147. Ref = gun:options(ConnPid, "*", [
  148. {<<"accept-encoding">>, <<"gzip">>}
  149. ]),
  150. {response, fin, 200, Headers} = gun:await(ConnPid, Ref),
  151. {_, <<"0">>} = lists:keyfind(<<"content-length">>, 1, Headers),
  152. ok.
  153. method_trace(Config) ->
  154. doc("The TRACE method is currently not implemented. (RFC7231 4.3.8)"),
  155. ConnPid = gun_open(Config),
  156. Ref = gun:request(ConnPid, <<"TRACE">>, "/", [
  157. {<<"accept-encoding">>, <<"gzip">>}
  158. ]),
  159. {response, fin, 501, _} = gun:await(ConnPid, Ref),
  160. ok.
  161. %% Request headers.
  162. %% @todo
  163. %% Status codes.
  164. http10_status_code_100(Config) ->
  165. case config(protocol, Config) of
  166. http ->
  167. doc("The 100 Continue status code must not "
  168. "be sent to HTTP/1.0 endpoints. (RFC7231 6.2)"),
  169. do_http10_status_code_1xx(100, Config);
  170. http2 ->
  171. status_code_100(Config)
  172. end.
  173. http10_status_code_101(Config) ->
  174. case config(protocol, Config) of
  175. http ->
  176. doc("The 101 Switching Protocols status code must not "
  177. "be sent to HTTP/1.0 endpoints. (RFC7231 6.2)"),
  178. do_http10_status_code_1xx(101, Config);
  179. http2 ->
  180. status_code_101(Config)
  181. end.
  182. do_http10_status_code_1xx(StatusCode, Config) ->
  183. ConnPid = gun_open([{http_opts, #{version => 'HTTP/1.0'}}|Config]),
  184. Ref = gun:get(ConnPid, "/resp/inform2/" ++ integer_to_list(StatusCode), [
  185. {<<"accept-encoding">>, <<"gzip">>}
  186. ]),
  187. {response, _, 200, _} = gun:await(ConnPid, Ref),
  188. ok.
  189. status_code_100(Config) ->
  190. doc("The 100 Continue status code can be sent. (RFC7231 6.2.1)"),
  191. ConnPid = gun_open(Config),
  192. Ref = gun:get(ConnPid, "/resp/inform2/100", [
  193. {<<"accept-encoding">>, <<"gzip">>}
  194. ]),
  195. {inform, 100, []} = gun:await(ConnPid, Ref),
  196. ok.
  197. status_code_101(Config) ->
  198. doc("The 101 Switching Protocols status code can be sent. (RFC7231 6.2.2)"),
  199. ConnPid = gun_open(Config),
  200. Ref = gun:get(ConnPid, "/resp/inform2/101", [
  201. {<<"accept-encoding">>, <<"gzip">>}
  202. ]),
  203. {inform, 101, []} = gun:await(ConnPid, Ref),
  204. ok.
  205. status_code_200(Config) ->
  206. doc("The 200 OK status code can be sent. (RFC7231 6.3.1)"),
  207. ConnPid = gun_open(Config),
  208. Ref = gun:get(ConnPid, "/resp/reply2/200", [
  209. {<<"accept-encoding">>, <<"gzip">>}
  210. ]),
  211. {response, _, 200, _} = gun:await(ConnPid, Ref),
  212. ok.
  213. status_code_201(Config) ->
  214. doc("The 201 Created status code can be sent. (RFC7231 6.3.2)"),
  215. ConnPid = gun_open(Config),
  216. Ref = gun:get(ConnPid, "/resp/reply2/201", [
  217. {<<"accept-encoding">>, <<"gzip">>}
  218. ]),
  219. {response, _, 201, _} = gun:await(ConnPid, Ref),
  220. ok.
  221. status_code_202(Config) ->
  222. doc("The 202 Accepted status code can be sent. (RFC7231 6.3.3)"),
  223. ConnPid = gun_open(Config),
  224. Ref = gun:get(ConnPid, "/resp/reply2/202", [
  225. {<<"accept-encoding">>, <<"gzip">>}
  226. ]),
  227. {response, _, 202, _} = gun:await(ConnPid, Ref),
  228. ok.
  229. status_code_203(Config) ->
  230. doc("The 203 Non-Authoritative Information status code can be sent. (RFC7231 6.3.4)"),
  231. ConnPid = gun_open(Config),
  232. Ref = gun:get(ConnPid, "/resp/reply2/203", [
  233. {<<"accept-encoding">>, <<"gzip">>}
  234. ]),
  235. {response, _, 203, _} = gun:await(ConnPid, Ref),
  236. ok.
  237. status_code_204(Config) ->
  238. doc("The 204 No Content status code can be sent. (RFC7231 6.3.5)"),
  239. ConnPid = gun_open(Config),
  240. Ref = gun:get(ConnPid, "/resp/reply2/204", [
  241. {<<"accept-encoding">>, <<"gzip">>}
  242. ]),
  243. {response, _, 204, _} = gun:await(ConnPid, Ref),
  244. ok.
  245. status_code_205(Config) ->
  246. doc("The 205 Reset Content status code can be sent. (RFC7231 6.3.6)"),
  247. ConnPid = gun_open(Config),
  248. Ref = gun:get(ConnPid, "/resp/reply2/205", [
  249. {<<"accept-encoding">>, <<"gzip">>}
  250. ]),
  251. {response, _, 205, _} = gun:await(ConnPid, Ref),
  252. ok.
  253. status_code_300(Config) ->
  254. doc("The 300 Multiple Choices status code can be sent. (RFC7231 6.4.1)"),
  255. ConnPid = gun_open(Config),
  256. Ref = gun:get(ConnPid, "/resp/reply2/300", [
  257. {<<"accept-encoding">>, <<"gzip">>}
  258. ]),
  259. {response, _, 300, _} = gun:await(ConnPid, Ref),
  260. ok.
  261. status_code_301(Config) ->
  262. doc("The 301 Moved Permanently status code can be sent. (RFC7231 6.4.2)"),
  263. ConnPid = gun_open(Config),
  264. Ref = gun:get(ConnPid, "/resp/reply2/301", [
  265. {<<"accept-encoding">>, <<"gzip">>}
  266. ]),
  267. {response, _, 301, _} = gun:await(ConnPid, Ref),
  268. ok.
  269. status_code_302(Config) ->
  270. doc("The 302 Found status code can be sent. (RFC7231 6.4.3)"),
  271. ConnPid = gun_open(Config),
  272. Ref = gun:get(ConnPid, "/resp/reply2/302", [
  273. {<<"accept-encoding">>, <<"gzip">>}
  274. ]),
  275. {response, _, 302, _} = gun:await(ConnPid, Ref),
  276. ok.
  277. status_code_303(Config) ->
  278. doc("The 303 See Other status code can be sent. (RFC7231 6.4.4)"),
  279. ConnPid = gun_open(Config),
  280. Ref = gun:get(ConnPid, "/resp/reply2/303", [
  281. {<<"accept-encoding">>, <<"gzip">>}
  282. ]),
  283. {response, _, 303, _} = gun:await(ConnPid, Ref),
  284. ok.
  285. status_code_305(Config) ->
  286. doc("The 305 Use Proxy status code can be sent. (RFC7231 6.4.5)"),
  287. ConnPid = gun_open(Config),
  288. Ref = gun:get(ConnPid, "/resp/reply2/305", [
  289. {<<"accept-encoding">>, <<"gzip">>}
  290. ]),
  291. {response, _, 305, _} = gun:await(ConnPid, Ref),
  292. ok.
  293. %% The status code 306 is no longer used. (RFC7231 6.4.6)
  294. status_code_307(Config) ->
  295. doc("The 307 Temporary Redirect status code can be sent. (RFC7231 6.4.7)"),
  296. ConnPid = gun_open(Config),
  297. Ref = gun:get(ConnPid, "/resp/reply2/307", [
  298. {<<"accept-encoding">>, <<"gzip">>}
  299. ]),
  300. {response, _, 307, _} = gun:await(ConnPid, Ref),
  301. ok.
  302. status_code_400(Config) ->
  303. doc("The 400 Bad Request status code can be sent. (RFC7231 6.5.1)"),
  304. ConnPid = gun_open(Config),
  305. Ref = gun:get(ConnPid, "/resp/reply2/400", [
  306. {<<"accept-encoding">>, <<"gzip">>}
  307. ]),
  308. {response, _, 400, _} = gun:await(ConnPid, Ref),
  309. ok.
  310. status_code_402(Config) ->
  311. doc("The 402 Payment Required status code can be sent. (RFC7231 6.5.2)"),
  312. ConnPid = gun_open(Config),
  313. Ref = gun:get(ConnPid, "/resp/reply2/402", [
  314. {<<"accept-encoding">>, <<"gzip">>}
  315. ]),
  316. {response, _, 402, _} = gun:await(ConnPid, Ref),
  317. ok.
  318. status_code_403(Config) ->
  319. doc("The 403 Forbidden status code can be sent. (RFC7231 6.5.3)"),
  320. ConnPid = gun_open(Config),
  321. Ref = gun:get(ConnPid, "/resp/reply2/403", [
  322. {<<"accept-encoding">>, <<"gzip">>}
  323. ]),
  324. {response, _, 403, _} = gun:await(ConnPid, Ref),
  325. ok.
  326. status_code_404(Config) ->
  327. doc("The 404 Not Found status code can be sent. (RFC7231 6.5.4)"),
  328. ConnPid = gun_open(Config),
  329. Ref = gun:get(ConnPid, "/resp/reply2/404", [
  330. {<<"accept-encoding">>, <<"gzip">>}
  331. ]),
  332. {response, _, 404, _} = gun:await(ConnPid, Ref),
  333. ok.
  334. status_code_405(Config) ->
  335. doc("The 405 Method Not Allowed status code can be sent. (RFC7231 6.5.5)"),
  336. ConnPid = gun_open(Config),
  337. Ref = gun:get(ConnPid, "/resp/reply2/405", [
  338. {<<"accept-encoding">>, <<"gzip">>}
  339. ]),
  340. {response, _, 405, _} = gun:await(ConnPid, Ref),
  341. ok.
  342. status_code_406(Config) ->
  343. doc("The 406 Not Acceptable status code can be sent. (RFC7231 6.5.6)"),
  344. ConnPid = gun_open(Config),
  345. Ref = gun:get(ConnPid, "/resp/reply2/406", [
  346. {<<"accept-encoding">>, <<"gzip">>}
  347. ]),
  348. {response, _, 406, _} = gun:await(ConnPid, Ref),
  349. ok.
  350. status_code_408(Config) ->
  351. doc("The 408 Request Timeout status code can be sent. (RFC7231 6.5.7)"),
  352. ConnPid = gun_open(Config),
  353. Ref = gun:get(ConnPid, "/resp/reply2/408", [
  354. {<<"accept-encoding">>, <<"gzip">>}
  355. ]),
  356. {response, _, 408, _} = gun:await(ConnPid, Ref),
  357. ok.
  358. status_code_409(Config) ->
  359. doc("The 409 Conflict status code can be sent. (RFC7231 6.5.8)"),
  360. ConnPid = gun_open(Config),
  361. Ref = gun:get(ConnPid, "/resp/reply2/409", [
  362. {<<"accept-encoding">>, <<"gzip">>}
  363. ]),
  364. {response, _, 409, _} = gun:await(ConnPid, Ref),
  365. ok.
  366. status_code_410(Config) ->
  367. doc("The 410 Gone status code can be sent. (RFC7231 6.5.9)"),
  368. ConnPid = gun_open(Config),
  369. Ref = gun:get(ConnPid, "/resp/reply2/410", [
  370. {<<"accept-encoding">>, <<"gzip">>}
  371. ]),
  372. {response, _, 410, _} = gun:await(ConnPid, Ref),
  373. ok.
  374. status_code_411(Config) ->
  375. doc("The 411 Length Required status code can be sent. (RFC7231 6.5.10)"),
  376. ConnPid = gun_open(Config),
  377. Ref = gun:get(ConnPid, "/resp/reply2/411", [
  378. {<<"accept-encoding">>, <<"gzip">>}
  379. ]),
  380. {response, _, 411, _} = gun:await(ConnPid, Ref),
  381. ok.
  382. status_code_413(Config) ->
  383. doc("The 413 Payload Too Large status code can be sent. (RFC7231 6.5.11)"),
  384. ConnPid = gun_open(Config),
  385. Ref = gun:get(ConnPid, "/resp/reply2/413", [
  386. {<<"accept-encoding">>, <<"gzip">>}
  387. ]),
  388. {response, _, 413, _} = gun:await(ConnPid, Ref),
  389. ok.
  390. status_code_414(Config) ->
  391. doc("The 414 URI Too Long status code can be sent. (RFC7231 6.5.12)"),
  392. ConnPid = gun_open(Config),
  393. Ref = gun:get(ConnPid, "/resp/reply2/414", [
  394. {<<"accept-encoding">>, <<"gzip">>}
  395. ]),
  396. {response, _, 414, _} = gun:await(ConnPid, Ref),
  397. ok.
  398. status_code_415(Config) ->
  399. doc("The 415 Unsupported Media Type status code can be sent. (RFC7231 6.5.13)"),
  400. ConnPid = gun_open(Config),
  401. Ref = gun:get(ConnPid, "/resp/reply2/415", [
  402. {<<"accept-encoding">>, <<"gzip">>}
  403. ]),
  404. {response, _, 415, _} = gun:await(ConnPid, Ref),
  405. ok.
  406. status_code_417(Config) ->
  407. doc("The 417 Expectation Failed status code can be sent. (RFC7231 6.5.14)"),
  408. ConnPid = gun_open(Config),
  409. Ref = gun:get(ConnPid, "/resp/reply2/417", [
  410. {<<"accept-encoding">>, <<"gzip">>}
  411. ]),
  412. {response, _, 417, _} = gun:await(ConnPid, Ref),
  413. ok.
  414. status_code_426(Config) ->
  415. doc("The 426 Upgrade Required status code can be sent. (RFC7231 6.5.15)"),
  416. ConnPid = gun_open(Config),
  417. Ref = gun:get(ConnPid, "/resp/reply2/426", [
  418. {<<"accept-encoding">>, <<"gzip">>}
  419. ]),
  420. {response, _, 426, _} = gun:await(ConnPid, Ref),
  421. ok.
  422. status_code_500(Config) ->
  423. doc("The 500 Internal Server Error status code can be sent. (RFC7231 6.6.1)"),
  424. ConnPid = gun_open(Config),
  425. Ref = gun:get(ConnPid, "/resp/reply2/500", [
  426. {<<"accept-encoding">>, <<"gzip">>}
  427. ]),
  428. {response, _, 500, _} = gun:await(ConnPid, Ref),
  429. ok.
  430. status_code_501(Config) ->
  431. doc("The 501 Not Implemented status code can be sent. (RFC7231 6.6.2)"),
  432. ConnPid = gun_open(Config),
  433. Ref = gun:get(ConnPid, "/resp/reply2/501", [
  434. {<<"accept-encoding">>, <<"gzip">>}
  435. ]),
  436. {response, _, 501, _} = gun:await(ConnPid, Ref),
  437. ok.
  438. status_code_502(Config) ->
  439. doc("The 502 Bad Gateway status code can be sent. (RFC7231 6.6.3)"),
  440. ConnPid = gun_open(Config),
  441. Ref = gun:get(ConnPid, "/resp/reply2/502", [
  442. {<<"accept-encoding">>, <<"gzip">>}
  443. ]),
  444. {response, _, 502, _} = gun:await(ConnPid, Ref),
  445. ok.
  446. status_code_503(Config) ->
  447. doc("The 503 Service Unavailable status code can be sent. (RFC7231 6.6.4)"),
  448. ConnPid = gun_open(Config),
  449. Ref = gun:get(ConnPid, "/resp/reply2/503", [
  450. {<<"accept-encoding">>, <<"gzip">>}
  451. ]),
  452. {response, _, 503, _} = gun:await(ConnPid, Ref),
  453. ok.
  454. status_code_504(Config) ->
  455. doc("The 504 Gateway Timeout status code can be sent. (RFC7231 6.6.5)"),
  456. ConnPid = gun_open(Config),
  457. Ref = gun:get(ConnPid, "/resp/reply2/504", [
  458. {<<"accept-encoding">>, <<"gzip">>}
  459. ]),
  460. {response, _, 504, _} = gun:await(ConnPid, Ref),
  461. ok.
  462. status_code_505(Config) ->
  463. doc("The 505 HTTP Version Not Supported status code can be sent. (RFC7231 6.6.6)"),
  464. ConnPid = gun_open(Config),
  465. Ref = gun:get(ConnPid, "/resp/reply2/505", [
  466. {<<"accept-encoding">>, <<"gzip">>}
  467. ]),
  468. {response, _, 505, _} = gun:await(ConnPid, Ref),
  469. ok.