http_SUITE.erl 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. %% Copyright (c) 2011-2017, Loïc Hoguin <essen@ninenines.eu>
  2. %% Copyright (c) 2011, Anthony Ramine <nox@dev-extend.eu>
  3. %%
  4. %% Permission to use, copy, modify, and/or distribute this software for any
  5. %% purpose with or without fee is hereby granted, provided that the above
  6. %% copyright notice and this permission notice appear in all copies.
  7. %%
  8. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. -module(http_SUITE).
  16. -compile(export_all).
  17. -import(ct_helper, [config/2]).
  18. -import(cowboy_test, [gun_open/1]).
  19. -import(cowboy_test, [gun_open/2]).
  20. -import(cowboy_test, [gun_down/1]).
  21. -import(cowboy_test, [raw_open/1]).
  22. -import(cowboy_test, [raw_send/2]).
  23. -import(cowboy_test, [raw_recv_head/1]).
  24. -import(cowboy_test, [raw_expect_recv/2]).
  25. %% ct.
  26. all() ->
  27. [
  28. {group, http},
  29. {group, https},
  30. {group, http_compress},
  31. {group, https_compress},
  32. {group, parse_host},
  33. {group, set_env}
  34. ].
  35. groups() ->
  36. Tests = ct_helper:all(?MODULE) -- [
  37. parse_host, set_env_dispatch
  38. ],
  39. [
  40. {http, [], Tests}, %% @todo parallel
  41. {https, [parallel], Tests},
  42. {http_compress, [parallel], Tests},
  43. {https_compress, [parallel], Tests},
  44. {parse_host, [], [
  45. parse_host
  46. ]},
  47. {set_env, [], [
  48. set_env_dispatch
  49. ]}
  50. ].
  51. init_per_suite(Config) ->
  52. Dir = config(priv_dir, Config) ++ "/static",
  53. ct_helper:create_static_dir(Dir),
  54. [{static_dir, Dir}|Config].
  55. end_per_suite(Config) ->
  56. ct_helper:delete_static_dir(config(static_dir, Config)).
  57. init_per_group(Name = http, Config) ->
  58. cowboy_test:init_http(Name, #{env => #{dispatch => init_dispatch(Config)}}, Config);
  59. init_per_group(Name = https, Config) ->
  60. cowboy_test:init_https(Name, #{env => #{dispatch => init_dispatch(Config)}}, Config);
  61. init_per_group(Name = http_compress, Config) ->
  62. cowboy_test:init_http(Name, #{
  63. env => #{dispatch => init_dispatch(Config)},
  64. compress => true
  65. }, Config);
  66. init_per_group(Name = https_compress, Config) ->
  67. cowboy_test:init_https(Name, #{
  68. env => #{dispatch => init_dispatch(Config)},
  69. compress => true
  70. }, Config);
  71. init_per_group(parse_host, Config) ->
  72. Dispatch = cowboy_router:compile([
  73. {'_', [
  74. {"/req_attr", http_req_attr, []}
  75. ]}
  76. ]),
  77. {ok, _} = cowboy:start_clear(parse_host, [{port, 0}], [
  78. {env, [{dispatch, Dispatch}]}
  79. ]),
  80. Port = ranch:get_port(parse_host),
  81. [{type, tcp}, {port, Port}, {opts, []}|Config];
  82. init_per_group(set_env, Config) ->
  83. {ok, _} = cowboy:start_clear(set_env, [{port, 0}], [
  84. {env, [{dispatch, []}]}
  85. ]),
  86. Port = ranch:get_port(set_env),
  87. [{type, tcp}, {port, Port}, {opts, []}|Config].
  88. end_per_group(Name, _) ->
  89. ok = cowboy:stop_listener(Name).
  90. %% Dispatch configuration.
  91. init_dispatch(Config) ->
  92. cowboy_router:compile([
  93. {"localhost", [
  94. {"/chunked_response", http_chunked, []},
  95. {"/streamed_response", http_streamed, []},
  96. {"/headers/dupe", http_handler,
  97. [{headers, #{<<"connection">> => <<"close">>}}]},
  98. {"/set_resp/header", http_set_resp,
  99. [{headers, #{<<"vary">> => <<"Accept">>}}]},
  100. {"/set_resp/overwrite", http_set_resp,
  101. [{headers, #{<<"server">> => <<"DesireDrive/1.0">>}}]},
  102. {"/set_resp/body", http_set_resp,
  103. [{body, <<"A flameless dance does not equal a cycle">>}]},
  104. {"/stream_body/set_resp", http_stream_body,
  105. [{reply, set_resp}, {body, <<"stream_body_set_resp">>}]},
  106. {"/stream_body/set_resp_close",
  107. http_stream_body, [
  108. {reply, set_resp_close},
  109. {body, <<"stream_body_set_resp_close">>}]},
  110. {"/stream_body/set_resp_chunked",
  111. http_stream_body, [
  112. {reply, set_resp_chunked},
  113. {body, [<<"stream_body">>, <<"_set_resp_chunked">>]}]},
  114. {"/static/[...]", cowboy_static,
  115. {dir, config(static_dir, Config)}},
  116. {"/static_mimetypes_function/[...]", cowboy_static,
  117. {dir, config(static_dir, Config),
  118. [{mimetypes, ?MODULE, do_mimetypes_text_html}]}},
  119. {"/handler_errors", http_errors, []},
  120. {"/static_attribute_etag/[...]", cowboy_static,
  121. {dir, config(static_dir, Config)}},
  122. {"/static_function_etag/[...]", cowboy_static,
  123. {dir, config(static_dir, Config),
  124. [{etag, ?MODULE, do_etag_gen}]}},
  125. {"/static_specify_file/[...]", cowboy_static,
  126. {file, config(static_dir, Config) ++ "/style.css"}},
  127. {"/echo/body", http_echo_body, []},
  128. {"/echo/body_qs", http_body_qs, []},
  129. {"/crash/content-length", input_crash_h, content_length},
  130. {"/param_all", rest_param_all, []},
  131. {"/bad_accept", rest_simple_resource, []},
  132. {"/bad_content_type", rest_patch_resource, []},
  133. {"/simple", rest_simple_resource, []},
  134. {"/forbidden_post", rest_forbidden_resource, [true]},
  135. {"/simple_post", rest_forbidden_resource, [false]},
  136. {"/missing_get_callbacks", rest_missing_callbacks, []},
  137. {"/missing_put_callbacks", rest_missing_callbacks, []},
  138. {"/nodelete", rest_nodelete_resource, []},
  139. {"/post_charset", rest_post_charset_resource, []},
  140. {"/postonly", rest_postonly_resource, []},
  141. {"/patch", rest_patch_resource, []},
  142. {"/resetags", rest_resource_etags, []},
  143. {"/rest_expires", rest_expires, []},
  144. {"/rest_expires_binary", rest_expires_binary, []},
  145. {"/rest_empty_resource", rest_empty_resource, []},
  146. {"/loop_stream_recv", http_loop_stream_recv, []},
  147. {"/", http_handler, []}
  148. ]}
  149. ]).
  150. %% Callbacks.
  151. do_etag_gen(_, _, _) ->
  152. {strong, <<"etag">>}.
  153. do_mimetypes_text_html(_) ->
  154. <<"text/html">>.
  155. %% Convenience functions.
  156. do_raw(Data, Config) ->
  157. Client = raw_open(Config),
  158. ok = raw_send(Client, Data),
  159. case catch raw_recv_head(Client) of
  160. {'EXIT', _} -> closed;
  161. Resp -> element(2, cow_http:parse_status_line(Resp))
  162. end.
  163. do_get(Path, Config) ->
  164. ConnPid = gun_open(Config),
  165. Ref = gun:get(ConnPid, Path),
  166. {response, _, Status, _} = gun:await(ConnPid, Ref),
  167. gun:close(ConnPid),
  168. Status.
  169. %% Tests.
  170. check_raw_status(Config) ->
  171. Huge = [$0 || _ <- lists:seq(1, 5000)],
  172. HugeCookie = lists:flatten(["whatever_man_biiiiiiiiiiiig_cookie_me_want_77="
  173. "Wed Apr 06 2011 10:38:52 GMT-0500 (CDT)" || _ <- lists:seq(1, 40)]),
  174. ResponsePacket =
  175. "HTTP/1.0 302 Found\r
  176. Location: http://www.google.co.il/\r
  177. Cache-Control: private\r
  178. Content-Type: text/html; charset=UTF-8\r
  179. Set-Cookie: PREF=ID=568f67013d4a7afa:FF=0:TM=1323014101:LM=1323014101:S=XqctDWC65MzKT0zC; expires=Tue, 03-Dec-2013 15:55:01 GMT; path=/; domain=.google.com\r
  180. Date: Sun, 04 Dec 2011 15:55:01 GMT\r
  181. Server: gws\r
  182. Content-Length: 221\r
  183. X-XSS-Protection: 1; mode=block\r
  184. X-Frame-Options: SAMEORIGIN\r
  185. \r
  186. <HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
  187. <TITLE>302 Moved</TITLE></HEAD><BODY>
  188. <H1>302 Moved</H1>
  189. The document has moved
  190. <A HREF=\"http://www.google.co.il/\">here</A>.
  191. </BODY></HTML>",
  192. Tests = [
  193. {200, ["GET / HTTP/1.0\r\nHost: localhost\r\n"
  194. "Set-Cookie: ", HugeCookie, "\r\n\r\n"]},
  195. {200, "\r\n\r\n\r\n\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  196. {200, "GET http://proxy/ HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  197. {400, "\n"},
  198. {400, "Garbage\r\n\r\n"},
  199. {400, "\r\n\r\n\r\n\r\n\r\n\r\n"},
  200. {400, " / HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  201. {400, "GET HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  202. {400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"},
  203. {400, "GET http://proxy/ HTTP/1.1\r\n\r\n"},
  204. {400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"},
  205. {400, ["POST /crash/content-length HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5000,5000\r\n\r\n", Huge]},
  206. {505, ResponsePacket},
  207. {408, "GET / HTTP/1.1\r\n"},
  208. {408, "GET / HTTP/1.1\r\nHost: localhost"},
  209. {408, "GET / HTTP/1.1\r\nHost: localhost\r\n"},
  210. {408, "GET / HTTP/1.1\r\nHost: localhost\r\n\r"},
  211. {414, Huge},
  212. {400, "GET / HTTP/1.1\r\n" ++ Huge},
  213. {505, "GET / HTTP/1.2\r\nHost: localhost\r\n\r\n"},
  214. {closed, ""},
  215. {closed, "\r\n"},
  216. {closed, "\r\n\r\n"},
  217. {closed, "GET / HTTP/1.1"}
  218. ],
  219. _ = [{Status, Packet} = begin
  220. Ret = do_raw(Packet, Config),
  221. {Ret, Packet}
  222. end || {Status, Packet} <- Tests],
  223. ok.
  224. check_status(Config) ->
  225. Tests = [
  226. {200, "/"},
  227. {200, "/simple"},
  228. {400, "/static/%2f"},
  229. {400, "/static/%2e"},
  230. {400, "/static/%2e%2e"},
  231. {403, "/static/directory"},
  232. {403, "/static/directory/"},
  233. {403, "/static/unreadable"},
  234. {404, "/not/found"},
  235. {404, "/static/not_found"},
  236. {500, "/handler_errors?case=init_before_reply"}
  237. ],
  238. _ = [{Status, URL} = begin
  239. Ret = do_get(URL, Config),
  240. {Ret, URL}
  241. end || {Status, URL} <- Tests].
  242. chunked_response(Config) ->
  243. ConnPid = gun_open(Config),
  244. Ref = gun:get(ConnPid, "/chunked_response"),
  245. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  246. true = lists:keymember(<<"transfer-encoding">>, 1, Headers),
  247. {ok, <<"chunked_handler\r\nworks fine!">>} = gun:await_body(ConnPid, Ref),
  248. ok.
  249. %% Check if sending requests whose size is around the MTU breaks something.
  250. echo_body(Config) ->
  251. MTU = ct_helper:get_loopback_mtu(),
  252. _ = [begin
  253. Body = list_to_binary(lists:duplicate(Size, $a)),
  254. ConnPid = gun_open(Config),
  255. Ref = gun:post(ConnPid, "/echo/body", [], Body),
  256. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  257. {ok, Body} = gun:await_body(ConnPid, Ref)
  258. end || Size <- lists:seq(MTU - 500, MTU)],
  259. ok.
  260. %% Check if sending request whose size is bigger than 1000000 bytes causes 413
  261. echo_body_max_length(Config) ->
  262. ConnPid = gun_open(Config),
  263. Ref = gun:post(ConnPid, "/echo/body", [], << 0:10000000/unit:8 >>),
  264. {response, nofin, 413, _} = gun:await(ConnPid, Ref),
  265. ok.
  266. % check if body_qs echo's back results
  267. echo_body_qs(Config) ->
  268. ConnPid = gun_open(Config),
  269. Ref = gun:post(ConnPid, "/echo/body_qs", [], <<"echo=67890">>),
  270. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  271. {ok, <<"67890">>} = gun:await_body(ConnPid, Ref),
  272. ok.
  273. echo_body_qs_max_length(Config) ->
  274. ConnPid = gun_open(Config),
  275. Ref = gun:post(ConnPid, "/echo/body_qs", [], << "echo=", 0:2000000/unit:8 >>),
  276. {response, nofin, 413, _} = gun:await(ConnPid, Ref),
  277. ok.
  278. error_init_after_reply(Config) ->
  279. ConnPid = gun_open(Config),
  280. Ref = gun:get(ConnPid, "/handler_errors?case=init_after_reply"),
  281. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  282. ok.
  283. headers_dupe(Config) ->
  284. ConnPid = gun_open(Config),
  285. Ref = gun:get(ConnPid, "/headers/dupe"),
  286. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  287. %% Ensure that only one connection header was received.
  288. [<<"close">>] = [V || {Name, V} <- Headers, Name =:= <<"connection">>],
  289. gun_down(ConnPid).
  290. http10_chunkless(Config) ->
  291. ConnPid = gun_open(Config, #{http_opts => #{version => 'HTTP/1.0'}}),
  292. Ref = gun:get(ConnPid, "/chunked_response"),
  293. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  294. false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
  295. {ok, <<"chunked_handler\r\nworks fine!">>} = gun:await_body(ConnPid, Ref),
  296. gun_down(ConnPid).
  297. http10_hostless(Config) ->
  298. Name = http10_hostless,
  299. Port10 = config(port, Config) + 10,
  300. {Transport, Protocol} = case config(type, Config) of
  301. tcp -> {ranch_tcp, cowboy_clear};
  302. ssl -> {ranch_ssl, cowboy_tls}
  303. end,
  304. ranch:start_listener(Name, 5, Transport,
  305. config(opts, Config) ++ [{port, Port10}],
  306. Protocol, #{
  307. env =>#{dispatch => cowboy_router:compile([
  308. {'_', [{"/http1.0/hostless", http_handler, []}]}])},
  309. max_keepalive => 50,
  310. timeout => 500
  311. }),
  312. 200 = do_raw("GET /http1.0/hostless HTTP/1.0\r\n\r\n",
  313. [{port, Port10}|Config]),
  314. cowboy:stop_listener(http10_hostless).
  315. http10_keepalive_default(Config) ->
  316. Normal = "GET / HTTP/1.0\r\nhost: localhost\r\n\r\n",
  317. Client = raw_open(Config),
  318. ok = raw_send(Client, Normal),
  319. case catch raw_recv_head(Client) of
  320. {'EXIT', _} -> error(closed);
  321. Data ->
  322. %% Cowboy always advertises itself as HTTP/1.1.
  323. {'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
  324. {Headers, _} = cow_http:parse_headers(Rest),
  325. {_, <<"close">>} = lists:keyfind(<<"connection">>, 1, Headers)
  326. end,
  327. ok = raw_send(Client, Normal),
  328. case catch raw_recv_head(Client) of
  329. {'EXIT', _} -> closed;
  330. _ -> error(not_closed)
  331. end.
  332. http10_keepalive_forced(Config) ->
  333. Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
  334. Client = raw_open(Config),
  335. ok = raw_send(Client, Keepalive),
  336. case catch raw_recv_head(Client) of
  337. {'EXIT', _} -> error(closed);
  338. Data ->
  339. %% Cowboy always advertises itself as HTTP/1.1.
  340. {'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
  341. {Headers, _} = cow_http:parse_headers(Rest),
  342. {_, <<"keep-alive">>} = lists:keyfind(<<"connection">>, 1, Headers)
  343. end,
  344. ok = raw_send(Client, Keepalive),
  345. case catch raw_recv_head(Client) of
  346. {'EXIT', Err} -> error({closed, Err});
  347. _ -> ok
  348. end.
  349. keepalive_max(Config) ->
  350. ConnPid = gun_open(Config),
  351. Refs = [gun:get(ConnPid, "/", [{<<"connection">>, <<"keep-alive">>}])
  352. || _ <- lists:seq(1, 99)],
  353. CloseRef = gun:get(ConnPid, "/", [{<<"connection">>, <<"keep-alive">>}]),
  354. _ = [begin
  355. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  356. false = lists:keymember(<<"connection">>, 1, Headers)
  357. end || Ref <- Refs],
  358. {response, nofin, 200, Headers} = gun:await(ConnPid, CloseRef),
  359. {_, <<"close">>} = lists:keyfind(<<"connection">>, 1, Headers),
  360. gun_down(ConnPid).
  361. keepalive_nl(Config) ->
  362. ConnPid = gun_open(Config),
  363. Refs = [begin
  364. Ref = gun:get(ConnPid, "/", [{<<"connection">>, <<"keep-alive">>}]),
  365. gun:dbg_send_raw(ConnPid, <<"\r\n">>),
  366. Ref
  367. end || _ <- lists:seq(1, 10)],
  368. _ = [begin
  369. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  370. false = lists:keymember(<<"connection">>, 1, Headers)
  371. end || Ref <- Refs],
  372. ok.
  373. keepalive_stream_loop(Config) ->
  374. ConnPid = gun_open(Config),
  375. Refs = [begin
  376. Ref = gun:post(ConnPid, "/loop_stream_recv",
  377. [{<<"content-type">>, <<"application/octet-stream">>}]),
  378. _ = [gun:data(ConnPid, Ref, nofin, << ID:32 >>)
  379. || ID <- lists:seq(1, 250)],
  380. gun:data(ConnPid, Ref, fin, <<>>),
  381. Ref
  382. end || _ <- lists:seq(1, 10)],
  383. _ = [begin
  384. {response, fin, 200, _} = gun:await(ConnPid, Ref)
  385. end || Ref <- Refs],
  386. ok.
  387. do_nc(Config, Input) ->
  388. Cat = os:find_executable("cat"),
  389. Nc = os:find_executable("nc"),
  390. case {Cat, Nc} of
  391. {false, _} ->
  392. {skip, {notfound, cat}};
  393. {_, false} ->
  394. {skip, {notfound, nc}};
  395. _Good ->
  396. %% Throw garbage at the server then check if it's still up.
  397. StrPort = integer_to_list(config(port, Config)),
  398. [os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort)
  399. || _ <- lists:seq(1, 100)],
  400. 200 = do_get("/", Config)
  401. end.
  402. nc_rand(Config) ->
  403. do_nc(Config, "/dev/urandom").
  404. nc_zero(Config) ->
  405. do_nc(Config, "/dev/zero").
  406. parse_host(Config) ->
  407. ConnPid = gun_open(Config),
  408. Tests = [
  409. {<<"example.org:8080">>, <<"example.org\n8080">>},
  410. {<<"example.org">>, <<"example.org\n80">>},
  411. {<<"192.0.2.1:8080">>, <<"192.0.2.1\n8080">>},
  412. {<<"192.0.2.1">>, <<"192.0.2.1\n80">>},
  413. {<<"[2001:db8::1]:8080">>, <<"[2001:db8::1]\n8080">>},
  414. {<<"[2001:db8::1]">>, <<"[2001:db8::1]\n80">>},
  415. {<<"[::ffff:192.0.2.1]:8080">>, <<"[::ffff:192.0.2.1]\n8080">>},
  416. {<<"[::ffff:192.0.2.1]">>, <<"[::ffff:192.0.2.1]\n80">>}
  417. ],
  418. [begin
  419. Ref = gun:get(ConnPid, "/req_attr?attr=host_and_port",
  420. [{<<"host">>, Host}]),
  421. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  422. {ok, Body} = gun:await_body(ConnPid, Ref)
  423. end || {Host, Body} <- Tests],
  424. ok.
  425. pipeline(Config) ->
  426. ConnPid = gun_open(Config),
  427. Refs = [gun:get(ConnPid, "/") || _ <- lists:seq(1, 5)],
  428. _ = [{response, nofin, 200, _} = gun:await(ConnPid, Ref) || Ref <- Refs],
  429. ok.
  430. rest_param_all(Config) ->
  431. ConnPid = gun_open(Config),
  432. %% Accept without param.
  433. Ref1 = gun:get(ConnPid, "/param_all",
  434. [{<<"accept">>, <<"text/plain">>}]),
  435. {response, nofin, 200, _} = gun:await(ConnPid, Ref1),
  436. {ok, <<"[]">>} = gun:await_body(ConnPid, Ref1),
  437. %% Accept with param.
  438. Ref2 = gun:get(ConnPid, "/param_all",
  439. [{<<"accept">>, <<"text/plain;level=1">>}]),
  440. {response, nofin, 200, _} = gun:await(ConnPid, Ref2),
  441. {ok, <<"level=1">>} = gun:await_body(ConnPid, Ref2),
  442. %% Accept with param and quality.
  443. Ref3 = gun:get(ConnPid, "/param_all",
  444. [{<<"accept">>, <<"text/plain;level=1;q=0.8, text/plain;level=2;q=0.5">>}]),
  445. {response, nofin, 200, _} = gun:await(ConnPid, Ref3),
  446. {ok, <<"level=1">>} = gun:await_body(ConnPid, Ref3),
  447. Ref4 = gun:get(ConnPid, "/param_all",
  448. [{<<"accept">>, <<"text/plain;level=1;q=0.5, text/plain;level=2;q=0.8">>}]),
  449. {response, nofin, 200, _} = gun:await(ConnPid, Ref4),
  450. {ok, <<"level=2">>} = gun:await_body(ConnPid, Ref4),
  451. %% Without Accept.
  452. Ref5 = gun:get(ConnPid, "/param_all"),
  453. {response, nofin, 200, _} = gun:await(ConnPid, Ref5),
  454. {ok, <<"'*'">>} = gun:await_body(ConnPid, Ref5),
  455. %% Content-Type without param.
  456. Ref6 = gun:put(ConnPid, "/param_all",
  457. [{<<"content-type">>, <<"text/plain">>}]),
  458. gun:data(ConnPid, Ref6, fin, "Hello world!"),
  459. {response, fin, 204, _} = gun:await(ConnPid, Ref6),
  460. %% Content-Type with param.
  461. Ref7 = gun:put(ConnPid, "/param_all",
  462. [{<<"content-type">>, <<"text/plain; charset=utf-8">>}]),
  463. gun:data(ConnPid, Ref7, fin, "Hello world!"),
  464. {response, fin, 204, _} = gun:await(ConnPid, Ref7),
  465. ok.
  466. rest_bad_accept(Config) ->
  467. ConnPid = gun_open(Config),
  468. Ref = gun:get(ConnPid, "/bad_accept",
  469. [{<<"accept">>, <<"1">>}]),
  470. {response, fin, 400, _} = gun:await(ConnPid, Ref),
  471. ok.
  472. rest_bad_content_type(Config) ->
  473. ConnPid = gun_open(Config),
  474. Ref = gun:patch(ConnPid, "/bad_content_type",
  475. [{<<"content-type">>, <<"text/plain, text/html">>}], <<"Whatever">>),
  476. {response, fin, 415, _} = gun:await(ConnPid, Ref),
  477. ok.
  478. rest_expires(Config) ->
  479. ConnPid = gun_open(Config),
  480. Ref = gun:get(ConnPid, "/rest_expires"),
  481. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  482. {_, Expires} = lists:keyfind(<<"expires">>, 1, Headers),
  483. {_, LastModified} = lists:keyfind(<<"last-modified">>, 1, Headers),
  484. Expires = LastModified = <<"Fri, 21 Sep 2012 22:36:14 GMT">>,
  485. ok.
  486. rest_expires_binary(Config) ->
  487. ConnPid = gun_open(Config),
  488. Ref = gun:get(ConnPid, "/rest_expires_binary"),
  489. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  490. {_, <<"0">>} = lists:keyfind(<<"expires">>, 1, Headers),
  491. ok.
  492. rest_last_modified_undefined(Config) ->
  493. ConnPid = gun_open(Config),
  494. Ref = gun:get(ConnPid, "/simple",
  495. [{<<"if-modified-since">>, <<"Fri, 21 Sep 2012 22:36:14 GMT">>}]),
  496. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  497. ok.
  498. rest_keepalive(Config) ->
  499. ConnPid = gun_open(Config),
  500. Refs = [gun:get(ConnPid, "/simple") || _ <- lists:seq(1, 10)],
  501. _ = [begin
  502. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  503. false = lists:keymember(<<"connection">>, 1, Headers)
  504. end || Ref <- Refs],
  505. ok.
  506. rest_keepalive_post(Config) ->
  507. ConnPid = gun_open(Config),
  508. Refs = [begin
  509. Ref1 = gun:post(ConnPid, "/forbidden_post", [{<<"content-type">>, <<"text/plain">>}]),
  510. gun:data(ConnPid, Ref1, fin, "Hello world!"),
  511. Ref2 = gun:post(ConnPid, "/simple_post", [{<<"content-type">>, <<"text/plain">>}]),
  512. gun:data(ConnPid, Ref2, fin, "Hello world!"),
  513. {Ref1, Ref2}
  514. end || _ <- lists:seq(1, 5)],
  515. _ = [begin
  516. {response, fin, 403, Headers1} = gun:await(ConnPid, Ref1),
  517. false = lists:keymember(<<"connection">>, 1, Headers1),
  518. {response, fin, 303, Headers2} = gun:await(ConnPid, Ref2),
  519. false = lists:keymember(<<"connection">>, 1, Headers2)
  520. end || {Ref1, Ref2} <- Refs],
  521. ok.
  522. rest_missing_get_callbacks(Config) ->
  523. ConnPid = gun_open(Config),
  524. Ref = gun:get(ConnPid, "/missing_get_callbacks"),
  525. {response, fin, 500, _} = gun:await(ConnPid, Ref),
  526. ok.
  527. rest_missing_put_callbacks(Config) ->
  528. ConnPid = gun_open(Config),
  529. Ref = gun:put(ConnPid, "/missing_put_callbacks",
  530. [{<<"content-type">>, <<"application/json">>}], <<"{}">>),
  531. {response, fin, 500, _} = gun:await(ConnPid, Ref),
  532. ok.
  533. rest_nodelete(Config) ->
  534. ConnPid = gun_open(Config),
  535. Ref = gun:delete(ConnPid, "/nodelete"),
  536. {response, fin, 500, _} = gun:await(ConnPid, Ref),
  537. ok.
  538. rest_options_default(Config) ->
  539. ConnPid = gun_open(Config),
  540. Ref = gun:options(ConnPid, "/rest_empty_resource"),
  541. {response, fin, 200, Headers} = gun:await(ConnPid, Ref),
  542. {_, <<"HEAD, GET, OPTIONS">>} = lists:keyfind(<<"allow">>, 1, Headers),
  543. ok.
  544. rest_patch(Config) ->
  545. Tests = [
  546. {204, [{<<"content-type">>, <<"text/plain">>}], <<"whatever">>},
  547. {400, [{<<"content-type">>, <<"text/plain">>}], <<"false">>},
  548. {400, [{<<"content-type">>, <<"text/plain">>}], <<"stop">>},
  549. {415, [{<<"content-type">>, <<"application/json">>}], <<"bad_content_type">>}
  550. ],
  551. ConnPid = gun_open(Config),
  552. _ = [begin
  553. Ref = gun:patch(ConnPid, "/patch", Headers, Body),
  554. {response, fin, Status, _} = gun:await(ConnPid, Ref)
  555. end || {Status, Headers, Body} <- Tests],
  556. ok.
  557. rest_post_charset(Config) ->
  558. ConnPid = gun_open(Config),
  559. Ref = gun:post(ConnPid, "/post_charset",
  560. [{<<"content-type">>, <<"text/plain;charset=UTF-8">>}], "12345"),
  561. {response, fin, 204, _} = gun:await(ConnPid, Ref),
  562. ok.
  563. rest_postonly(Config) ->
  564. ConnPid = gun_open(Config),
  565. Ref = gun:post(ConnPid, "/postonly",
  566. [{<<"content-type">>, <<"text/plain">>}], "12345"),
  567. {response, fin, 204, _} = gun:await(ConnPid, Ref),
  568. ok.
  569. rest_resource_get_etag(Config, Type) ->
  570. rest_resource_get_etag(Config, Type, []).
  571. rest_resource_get_etag(Config, Type, Headers) ->
  572. ConnPid = gun_open(Config),
  573. Ref = gun:get(ConnPid, "/resetags?type=" ++ Type, Headers),
  574. {response, _, Status, RespHeaders} = gun:await(ConnPid, Ref),
  575. case lists:keyfind(<<"etag">>, 1, RespHeaders) of
  576. false -> {Status, false};
  577. {<<"etag">>, ETag} -> {Status, ETag}
  578. end.
  579. rest_resource_etags(Config) ->
  580. Tests = [
  581. {200, <<"W/\"etag-header-value\"">>, "tuple-weak"},
  582. {200, <<"\"etag-header-value\"">>, "tuple-strong"},
  583. {200, <<"W/\"etag-header-value\"">>, "binary-weak-quoted"},
  584. {200, <<"\"etag-header-value\"">>, "binary-strong-quoted"},
  585. {400, false, "binary-strong-unquoted"},
  586. {400, false, "binary-weak-unquoted"}
  587. ],
  588. _ = [{Status, ETag, Type} = begin
  589. {Ret, RespETag} = rest_resource_get_etag(Config, Type),
  590. {Ret, RespETag, Type}
  591. end || {Status, ETag, Type} <- Tests].
  592. rest_resource_etags_if_none_match(Config) ->
  593. Tests = [
  594. {304, <<"W/\"etag-header-value\"">>, "tuple-weak"},
  595. {304, <<"\"etag-header-value\"">>, "tuple-strong"},
  596. {304, <<"W/\"etag-header-value\"">>, "binary-weak-quoted"},
  597. {304, <<"\"etag-header-value\"">>, "binary-strong-quoted"}
  598. ],
  599. _ = [{Status, Type} = begin
  600. {Ret, _} = rest_resource_get_etag(Config, Type,
  601. [{<<"if-none-match">>, ETag}]),
  602. {Ret, Type}
  603. end || {Status, ETag, Type} <- Tests].
  604. set_env_dispatch(Config) ->
  605. ConnPid1 = gun_open(Config),
  606. Ref1 = gun:get(ConnPid1, "/"),
  607. {response, fin, 400, _} = gun:await(ConnPid1, Ref1),
  608. ok = cowboy:set_env(set_env, dispatch,
  609. cowboy_router:compile([{'_', [{"/", http_handler, []}]}])),
  610. ConnPid2 = gun_open(Config),
  611. Ref2 = gun:get(ConnPid2, "/"),
  612. {response, nofin, 200, _} = gun:await(ConnPid2, Ref2),
  613. ok.
  614. set_resp_body(Config) ->
  615. ConnPid = gun_open(Config),
  616. Ref = gun:get(ConnPid, "/set_resp/body"),
  617. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  618. {ok, <<"A flameless dance does not equal a cycle">>}
  619. = gun:await_body(ConnPid, Ref),
  620. ok.
  621. set_resp_header(Config) ->
  622. ConnPid = gun_open(Config),
  623. Ref = gun:get(ConnPid, "/set_resp/header"),
  624. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  625. {_, <<"Accept">>} = lists:keyfind(<<"vary">>, 1, Headers),
  626. {_, _} = lists:keyfind(<<"set-cookie">>, 1, Headers),
  627. ok.
  628. set_resp_overwrite(Config) ->
  629. ConnPid = gun_open(Config),
  630. Ref = gun:get(ConnPid, "/set_resp/overwrite"),
  631. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  632. {_, <<"DesireDrive/1.0">>} = lists:keyfind(<<"server">>, 1, Headers),
  633. ok.
  634. slowloris(Config) ->
  635. Client = raw_open(Config),
  636. try
  637. [begin
  638. ok = raw_send(Client, [C]),
  639. receive after 250 -> ok end
  640. end || C <- "GET / HTTP/1.1\r\nHost: localhost\r\n"
  641. "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US)\r\n"
  642. "Cookie: name=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n\r\n"],
  643. error(failure)
  644. catch error:{badmatch, _} ->
  645. ok
  646. end.
  647. slowloris2(Config) ->
  648. Client = raw_open(Config),
  649. ok = raw_send(Client, "GET / HTTP/1.1\r\n"),
  650. receive after 300 -> ok end,
  651. ok = raw_send(Client, "Host: localhost\r\n"),
  652. receive after 300 -> ok end,
  653. Data = raw_recv_head(Client),
  654. {_, 408, _, _} = cow_http:parse_status_line(Data),
  655. ok.
  656. static_attribute_etag(Config) ->
  657. ConnPid = gun_open(Config),
  658. Ref1 = gun:get(ConnPid, "/static_attribute_etag/index.html"),
  659. Ref2 = gun:get(ConnPid, "/static_attribute_etag/index.html"),
  660. {response, nofin, 200, Headers1} = gun:await(ConnPid, Ref1),
  661. {response, nofin, 200, Headers2} = gun:await(ConnPid, Ref2),
  662. {_, ETag} = lists:keyfind(<<"etag">>, 1, Headers1),
  663. {_, ETag} = lists:keyfind(<<"etag">>, 1, Headers2),
  664. true = ETag =/= undefined,
  665. ok.
  666. static_function_etag(Config) ->
  667. ConnPid = gun_open(Config),
  668. Ref1 = gun:get(ConnPid, "/static_function_etag/index.html"),
  669. Ref2 = gun:get(ConnPid, "/static_function_etag/index.html"),
  670. {response, nofin, 200, Headers1} = gun:await(ConnPid, Ref1),
  671. {response, nofin, 200, Headers2} = gun:await(ConnPid, Ref2),
  672. {_, ETag} = lists:keyfind(<<"etag">>, 1, Headers1),
  673. {_, ETag} = lists:keyfind(<<"etag">>, 1, Headers2),
  674. true = ETag =/= undefined,
  675. ok.
  676. static_mimetypes_function(Config) ->
  677. ConnPid = gun_open(Config),
  678. Ref = gun:get(ConnPid, "/static_mimetypes_function/index.html"),
  679. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  680. {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers),
  681. ok.
  682. static_specify_file(Config) ->
  683. ConnPid = gun_open(Config),
  684. Ref = gun:get(ConnPid, "/static_specify_file"),
  685. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  686. {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers),
  687. {ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, Ref),
  688. ok.
  689. static_specify_file_catchall(Config) ->
  690. ConnPid = gun_open(Config),
  691. Ref = gun:get(ConnPid, "/static_specify_file/none"),
  692. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  693. {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers),
  694. {ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, Ref),
  695. ok.
  696. static_test_file(Config) ->
  697. ConnPid = gun_open(Config),
  698. Ref = gun:get(ConnPid, "/static/unknown"),
  699. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  700. {_, <<"application/octet-stream">>} = lists:keyfind(<<"content-type">>, 1, Headers),
  701. ok.
  702. static_test_file_css(Config) ->
  703. ConnPid = gun_open(Config),
  704. Ref = gun:get(ConnPid, "/static/style.css"),
  705. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  706. {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers),
  707. ok.
  708. stream_body_set_resp(Config) ->
  709. ConnPid = gun_open(Config),
  710. Ref = gun:get(ConnPid, "/stream_body/set_resp"),
  711. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  712. {ok, <<"stream_body_set_resp">>} = gun:await_body(ConnPid, Ref),
  713. ok.
  714. stream_body_set_resp_close(Config) ->
  715. ConnPid = gun_open(Config),
  716. Ref = gun:get(ConnPid, "/stream_body/set_resp_close"),
  717. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  718. {ok, <<"stream_body_set_resp_close">>} = gun:await_body(ConnPid, Ref),
  719. gun_down(ConnPid).
  720. stream_body_set_resp_chunked(Config) ->
  721. ConnPid = gun_open(Config),
  722. Ref = gun:get(ConnPid, "/stream_body/set_resp_chunked"),
  723. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  724. {_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
  725. {ok, <<"stream_body_set_resp_chunked">>} = gun:await_body(ConnPid, Ref),
  726. ok.
  727. stream_body_set_resp_chunked10(Config) ->
  728. ConnPid = gun_open(Config, #{http_opts => #{version => 'HTTP/1.0'}}),
  729. Ref = gun:get(ConnPid, "/stream_body/set_resp_chunked"),
  730. {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
  731. false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
  732. {ok, <<"stream_body_set_resp_chunked">>} = gun:await_body(ConnPid, Ref),
  733. gun_down(ConnPid).
  734. %% Undocumented hack: force chunked response to be streamed as HTTP/1.1.
  735. streamed_response(Config) ->
  736. Client = raw_open(Config),
  737. ok = raw_send(Client, "GET /streamed_response HTTP/1.1\r\nHost: localhost\r\n\r\n"),
  738. Data = raw_recv_head(Client),
  739. {'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
  740. {Headers, Rest2} = cow_http:parse_headers(Rest),
  741. false = lists:keymember(<<"transfer-encoding">>, 1, Headers),
  742. Rest2Size = byte_size(Rest2),
  743. ok = case <<"streamed_handler\r\nworks fine!">> of
  744. Rest2 -> ok;
  745. << Rest2:Rest2Size/binary, Expect/bits >> -> raw_expect_recv(Client, Expect)
  746. end.
  747. te_chunked(Config) ->
  748. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  749. ConnPid = gun_open(Config),
  750. Ref = gun:post(ConnPid, "/echo/body", [{<<"content-type">>, <<"text/plain">>}]),
  751. gun:data(ConnPid, Ref, fin, Body),
  752. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  753. {ok, Body} = gun:await_body(ConnPid, Ref),
  754. ok.
  755. do_body_to_chunks(_, <<>>, Acc) ->
  756. lists:reverse([<<"0\r\n\r\n">>|Acc]);
  757. do_body_to_chunks(ChunkSize, Body, Acc) ->
  758. BodySize = byte_size(Body),
  759. ChunkSize2 = case BodySize < ChunkSize of
  760. true -> BodySize;
  761. false -> ChunkSize
  762. end,
  763. << Chunk:ChunkSize2/binary, Rest/binary >> = Body,
  764. ChunkSizeBin = integer_to_binary(ChunkSize2, 16),
  765. do_body_to_chunks(ChunkSize, Rest,
  766. [<< ChunkSizeBin/binary, "\r\n", Chunk/binary, "\r\n" >>|Acc]).
  767. te_chunked_chopped(Config) ->
  768. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  769. Body2 = iolist_to_binary(do_body_to_chunks(50, Body, [])),
  770. ConnPid = gun_open(Config),
  771. Ref = gun:post(ConnPid, "/echo/body",
  772. [{<<"content-type">>, <<"text/plain">>}]),
  773. _ = [begin
  774. ok = gun:dbg_send_raw(ConnPid, << C >>),
  775. receive after 10 -> ok end
  776. end || << C >> <= Body2],
  777. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  778. {ok, Body} = gun:await_body(ConnPid, Ref),
  779. ok.
  780. te_chunked_delayed(Config) ->
  781. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  782. Chunks = do_body_to_chunks(50, Body, []),
  783. ConnPid = gun_open(Config),
  784. Ref = gun:post(ConnPid, "/echo/body",
  785. [{<<"content-type">>, <<"text/plain">>}]),
  786. _ = [begin
  787. ok = gun:dbg_send_raw(ConnPid, Chunk),
  788. receive after 10 -> ok end
  789. end || Chunk <- Chunks],
  790. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  791. {ok, Body} = gun:await_body(ConnPid, Ref),
  792. ok.
  793. te_chunked_split_body(Config) ->
  794. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  795. Chunks = do_body_to_chunks(50, Body, []),
  796. ConnPid = gun_open(Config),
  797. Ref = gun:post(ConnPid, "/echo/body",
  798. [{<<"content-type">>, <<"text/plain">>}]),
  799. _ = [begin
  800. case Chunk of
  801. <<"0\r\n\r\n">> ->
  802. ok = gun:dbg_send_raw(ConnPid, Chunk);
  803. _ ->
  804. [Size, ChunkBody, <<>>] =
  805. binary:split(Chunk, [<<"\r\n">>], [global]),
  806. PartASize = random:uniform(byte_size(ChunkBody)),
  807. <<PartA:PartASize/binary, PartB/binary>> = ChunkBody,
  808. ok = gun:dbg_send_raw(ConnPid, [Size, <<"\r\n">>, PartA]),
  809. receive after 10 -> ok end,
  810. ok = gun:dbg_send_raw(ConnPid, [PartB, <<"\r\n">>])
  811. end
  812. end || Chunk <- Chunks],
  813. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  814. {ok, Body} = gun:await_body(ConnPid, Ref),
  815. ok.
  816. te_chunked_split_crlf(Config) ->
  817. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  818. Chunks = do_body_to_chunks(50, Body, []),
  819. ConnPid = gun_open(Config),
  820. Ref = gun:post(ConnPid, "/echo/body",
  821. [{<<"content-type">>, <<"text/plain">>}]),
  822. _ = [begin
  823. %% Split in the newline just before the end of the chunk.
  824. Len = byte_size(Chunk) - (random:uniform(2) - 1),
  825. << Chunk2:Len/binary, End/binary >> = Chunk,
  826. ok = gun:dbg_send_raw(ConnPid, Chunk2),
  827. receive after 10 -> ok end,
  828. ok = gun:dbg_send_raw(ConnPid, End)
  829. end || Chunk <- Chunks],
  830. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  831. {ok, Body} = gun:await_body(ConnPid, Ref),
  832. ok.
  833. te_identity(Config) ->
  834. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  835. ConnPid = gun_open(Config),
  836. Ref = gun:post(ConnPid, "/echo/body", [], Body),
  837. {response, nofin, 200, _} = gun:await(ConnPid, Ref),
  838. {ok, Body} = gun:await_body(ConnPid, Ref),
  839. ok.