http_SUITE.erl 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. %% Copyright (c) 2011-2013, 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. -include_lib("common_test/include/ct.hrl").
  17. %% ct.
  18. -export([all/0]).
  19. -export([groups/0]).
  20. -export([init_per_suite/1]).
  21. -export([end_per_suite/1]).
  22. -export([init_per_group/2]).
  23. -export([end_per_group/2]).
  24. %% Tests.
  25. -export([check_raw_status/1]).
  26. -export([check_status/1]).
  27. -export([chunked_response/1]).
  28. -export([echo_body/1]).
  29. -export([error_chain_handle_after_reply/1]).
  30. -export([error_chain_handle_before_reply/1]).
  31. -export([error_handle_after_reply/1]).
  32. -export([error_init_after_reply/1]).
  33. -export([error_init_reply_handle_error/1]).
  34. -export([headers_dupe/1]).
  35. -export([http10_chunkless/1]).
  36. -export([http10_hostless/1]).
  37. -export([keepalive_max/1]).
  38. -export([keepalive_nl/1]).
  39. -export([multipart/1]).
  40. -export([nc_rand/1]).
  41. -export([nc_zero/1]).
  42. -export([onrequest/1]).
  43. -export([onrequest_reply/1]).
  44. -export([onresponse_crash/1]).
  45. -export([onresponse_reply/1]).
  46. -export([pipeline/1]).
  47. -export([rest_bad_accept/1]).
  48. -export([rest_expires/1]).
  49. -export([rest_keepalive/1]).
  50. -export([rest_keepalive_post/1]).
  51. -export([rest_missing_get_callbacks/1]).
  52. -export([rest_missing_put_callbacks/1]).
  53. -export([rest_nodelete/1]).
  54. -export([rest_resource_etags/1]).
  55. -export([rest_resource_etags_if_none_match/1]).
  56. -export([set_resp_body/1]).
  57. -export([set_resp_header/1]).
  58. -export([set_resp_overwrite/1]).
  59. -export([static_attribute_etag/1]).
  60. -export([static_function_etag/1]).
  61. -export([static_mimetypes_function/1]).
  62. -export([static_specify_file/1]).
  63. -export([static_specify_file_catchall/1]).
  64. -export([static_test_file/1]).
  65. -export([static_test_file_css/1]).
  66. -export([stream_body_set_resp/1]).
  67. -export([stream_body_set_resp_close/1]).
  68. -export([te_chunked/1]).
  69. -export([te_chunked_delayed/1]).
  70. -export([te_identity/1]).
  71. %% ct.
  72. all() ->
  73. [{group, http}, {group, https}, {group, onrequest}, {group, onresponse}].
  74. groups() ->
  75. Tests = [
  76. check_raw_status,
  77. check_status,
  78. chunked_response,
  79. echo_body,
  80. error_chain_handle_after_reply,
  81. error_chain_handle_before_reply,
  82. error_handle_after_reply,
  83. error_init_after_reply,
  84. error_init_reply_handle_error,
  85. headers_dupe,
  86. http10_chunkless,
  87. http10_hostless,
  88. keepalive_max,
  89. keepalive_nl,
  90. multipart,
  91. nc_rand,
  92. nc_zero,
  93. pipeline,
  94. rest_bad_accept,
  95. rest_expires,
  96. rest_keepalive,
  97. rest_keepalive_post,
  98. rest_missing_get_callbacks,
  99. rest_missing_put_callbacks,
  100. rest_nodelete,
  101. rest_resource_etags,
  102. rest_resource_etags_if_none_match,
  103. set_resp_body,
  104. set_resp_header,
  105. set_resp_overwrite,
  106. static_attribute_etag,
  107. static_function_etag,
  108. static_mimetypes_function,
  109. static_specify_file,
  110. static_specify_file_catchall,
  111. static_test_file,
  112. static_test_file_css,
  113. stream_body_set_resp,
  114. stream_body_set_resp_close,
  115. te_chunked,
  116. te_chunked_delayed,
  117. te_identity
  118. ],
  119. [
  120. {http, [], Tests},
  121. {https, [], Tests},
  122. {onrequest, [], [
  123. onrequest,
  124. onrequest_reply
  125. ]},
  126. {onresponse, [], [
  127. onresponse_crash,
  128. onresponse_reply
  129. ]}
  130. ].
  131. init_per_suite(Config) ->
  132. application:start(inets),
  133. application:start(crypto),
  134. application:start(ranch),
  135. application:start(cowboy),
  136. Config.
  137. end_per_suite(_Config) ->
  138. application:stop(cowboy),
  139. application:stop(ranch),
  140. application:stop(crypto),
  141. application:stop(inets),
  142. ok.
  143. init_per_group(http, Config) ->
  144. Port = 33080,
  145. Transport = ranch_tcp,
  146. Config1 = init_static_dir(Config),
  147. {ok, _} = cowboy:start_http(http, 100, [{port, Port}], [
  148. {env, [{dispatch, init_dispatch(Config1)}]},
  149. {max_keepalive, 50},
  150. {timeout, 500}
  151. ]),
  152. {ok, Client} = cowboy_client:init([]),
  153. [{scheme, <<"http">>}, {port, Port}, {opts, []},
  154. {transport, Transport}, {client, Client}|Config1];
  155. init_per_group(https, Config) ->
  156. Port = 33081,
  157. Transport = ranch_ssl,
  158. Opts = [
  159. {certfile, ?config(data_dir, Config) ++ "cert.pem"},
  160. {keyfile, ?config(data_dir, Config) ++ "key.pem"},
  161. {password, "cowboy"}
  162. ],
  163. Config1 = init_static_dir(Config),
  164. application:start(public_key),
  165. application:start(ssl),
  166. {ok, _} = cowboy:start_https(https, 100, Opts ++ [{port, Port}], [
  167. {env, [{dispatch, init_dispatch(Config1)}]},
  168. {max_keepalive, 50},
  169. {timeout, 500}
  170. ]),
  171. {ok, Client} = cowboy_client:init(Opts),
  172. [{scheme, <<"https">>}, {port, Port}, {opts, Opts},
  173. {transport, Transport}, {client, Client}|Config1];
  174. init_per_group(onrequest, Config) ->
  175. Port = 33082,
  176. Transport = ranch_tcp,
  177. {ok, _} = cowboy:start_http(onrequest, 100, [{port, Port}], [
  178. {env, [{dispatch, init_dispatch(Config)}]},
  179. {max_keepalive, 50},
  180. {onrequest, fun onrequest_hook/1},
  181. {timeout, 500}
  182. ]),
  183. {ok, Client} = cowboy_client:init([]),
  184. [{scheme, <<"http">>}, {port, Port}, {opts, []},
  185. {transport, Transport}, {client, Client}|Config];
  186. init_per_group(onresponse, Config) ->
  187. Port = 33083,
  188. Transport = ranch_tcp,
  189. {ok, _} = cowboy:start_http(onresponse, 100, [{port, Port}], [
  190. {env, [{dispatch, init_dispatch(Config)}]},
  191. {max_keepalive, 50},
  192. {onresponse, fun onresponse_hook/4},
  193. {timeout, 500}
  194. ]),
  195. {ok, Client} = cowboy_client:init([]),
  196. [{scheme, <<"http">>}, {port, Port}, {opts, []},
  197. {transport, Transport}, {client, Client}|Config].
  198. end_per_group(https, Config) ->
  199. cowboy:stop_listener(https),
  200. application:stop(ssl),
  201. application:stop(public_key),
  202. end_static_dir(Config),
  203. ok;
  204. end_per_group(http, Config) ->
  205. cowboy:stop_listener(http),
  206. end_static_dir(Config);
  207. end_per_group(Name, _) ->
  208. cowboy:stop_listener(Name),
  209. ok.
  210. %% Dispatch configuration.
  211. init_dispatch(Config) ->
  212. [
  213. {[<<"localhost">>], [
  214. {[<<"chunked_response">>], chunked_handler, []},
  215. {[<<"init_shutdown">>], http_handler_init_shutdown, []},
  216. {[<<"long_polling">>], http_handler_long_polling, []},
  217. {[<<"headers">>, <<"dupe">>], http_handler,
  218. [{headers, [{<<"connection">>, <<"close">>}]}]},
  219. {[<<"set_resp">>, <<"header">>], http_handler_set_resp,
  220. [{headers, [{<<"vary">>, <<"Accept">>}]}]},
  221. {[<<"set_resp">>, <<"overwrite">>], http_handler_set_resp,
  222. [{headers, [{<<"server">>, <<"DesireDrive/1.0">>}]}]},
  223. {[<<"set_resp">>, <<"body">>], http_handler_set_resp,
  224. [{body, <<"A flameless dance does not equal a cycle">>}]},
  225. {[<<"stream_body">>, <<"set_resp">>], http_handler_stream_body,
  226. [{reply, set_resp}, {body, <<"stream_body_set_resp">>}]},
  227. {[<<"stream_body">>, <<"set_resp_close">>],
  228. http_handler_stream_body, [
  229. {reply, set_resp_close},
  230. {body, <<"stream_body_set_resp_close">>}]},
  231. {[<<"static">>, '...'], cowboy_static,
  232. [{directory, ?config(static_dir, Config)},
  233. {mimetypes, [{<<".css">>, [<<"text/css">>]}]}]},
  234. {[<<"static_mimetypes_function">>, '...'], cowboy_static,
  235. [{directory, ?config(static_dir, Config)},
  236. {mimetypes, {fun(Path, data) when is_binary(Path) ->
  237. [<<"text/html">>] end, data}}]},
  238. {[<<"handler_errors">>], http_handler_errors, []},
  239. {[<<"static_attribute_etag">>, '...'], cowboy_static,
  240. [{directory, ?config(static_dir, Config)},
  241. {etag, {attributes, [filepath, filesize, inode, mtime]}}]},
  242. {[<<"static_function_etag">>, '...'], cowboy_static,
  243. [{directory, ?config(static_dir, Config)},
  244. {etag, {fun static_function_etag/2, etag_data}}]},
  245. {[<<"static_specify_file">>, '...'], cowboy_static,
  246. [{directory, ?config(static_dir, Config)},
  247. {mimetypes, [{<<".css">>, [<<"text/css">>]}]},
  248. {file, <<"test_file.css">>}]},
  249. {[<<"multipart">>], http_handler_multipart, []},
  250. {[<<"echo">>, <<"body">>], http_handler_echo_body, []},
  251. {[<<"bad_accept">>], rest_simple_resource, []},
  252. {[<<"simple">>], rest_simple_resource, []},
  253. {[<<"forbidden_post">>], rest_forbidden_resource, [true]},
  254. {[<<"simple_post">>], rest_forbidden_resource, [false]},
  255. {[<<"missing_get_callbacks">>], rest_missing_callbacks, []},
  256. {[<<"missing_put_callbacks">>], rest_missing_callbacks, []},
  257. {[<<"nodelete">>], rest_nodelete_resource, []},
  258. {[<<"resetags">>], rest_resource_etags, []},
  259. {[<<"rest_expires">>], rest_expires, []},
  260. {[<<"loop_timeout">>], http_handler_loop_timeout, []},
  261. {[], http_handler, []}
  262. ]}
  263. ].
  264. init_static_dir(Config) ->
  265. Dir = filename:join(?config(priv_dir, Config), "static"),
  266. Level1 = fun(Name) -> filename:join(Dir, Name) end,
  267. ok = file:make_dir(Dir),
  268. ok = file:write_file(Level1("test_file"), "test_file\n"),
  269. ok = file:write_file(Level1("test_file.css"), "test_file.css\n"),
  270. ok = file:write_file(Level1("test_noread"), "test_noread\n"),
  271. ok = file:change_mode(Level1("test_noread"), 8#0333),
  272. ok = file:write_file(Level1("test.html"), "test.html\n"),
  273. ok = file:make_dir(Level1("test_dir")),
  274. [{static_dir, Dir}|Config].
  275. end_static_dir(Config) ->
  276. Dir = ?config(static_dir, Config),
  277. Level1 = fun(Name) -> filename:join(Dir, Name) end,
  278. ok = file:delete(Level1("test_file")),
  279. ok = file:delete(Level1("test_file.css")),
  280. ok = file:delete(Level1("test_noread")),
  281. ok = file:delete(Level1("test.html")),
  282. ok = file:del_dir(Level1("test_dir")),
  283. ok = file:del_dir(Dir),
  284. Config.
  285. %% Convenience functions.
  286. quick_raw(Data, Config) ->
  287. Client = ?config(client, Config),
  288. Transport = ?config(transport, Config),
  289. {ok, Client2} = cowboy_client:connect(
  290. Transport, "localhost", ?config(port, Config), Client),
  291. {ok, Client3} = cowboy_client:raw_request(Data, Client2),
  292. case cowboy_client:response(Client3) of
  293. {ok, Status, _, _} -> Status;
  294. {error, _} -> closed
  295. end.
  296. build_url(Path, Config) ->
  297. {scheme, Scheme} = lists:keyfind(scheme, 1, Config),
  298. {port, Port} = lists:keyfind(port, 1, Config),
  299. PortBin = list_to_binary(integer_to_list(Port)),
  300. PathBin = list_to_binary(Path),
  301. << Scheme/binary, "://localhost:", PortBin/binary, PathBin/binary >>.
  302. quick_get(URL, Config) ->
  303. Client = ?config(client, Config),
  304. {ok, Client2} = cowboy_client:request(<<"GET">>,
  305. build_url(URL, Config), Client),
  306. {ok, Status, _, _} = cowboy_client:response(Client2),
  307. Status.
  308. body_to_chunks(_, <<>>, Acc) ->
  309. lists:reverse([<<"0\r\n\r\n">>|Acc]);
  310. body_to_chunks(ChunkSize, Body, Acc) ->
  311. BodySize = byte_size(Body),
  312. ChunkSize2 = case BodySize < ChunkSize of
  313. true -> BodySize;
  314. false -> ChunkSize
  315. end,
  316. << Chunk:ChunkSize2/binary, Rest/binary >> = Body,
  317. ChunkSizeBin = list_to_binary(integer_to_list(ChunkSize2, 16)),
  318. body_to_chunks(ChunkSize, Rest,
  319. [<< ChunkSizeBin/binary, "\r\n", Chunk/binary, "\r\n" >>|Acc]).
  320. %% Tests.
  321. check_raw_status(Config) ->
  322. Huge = [$0 || _ <- lists:seq(1, 5000)],
  323. HugeCookie = lists:flatten(["whatever_man_biiiiiiiiiiiig_cookie_me_want_77="
  324. "Wed Apr 06 2011 10:38:52 GMT-0500 (CDT)" || _ <- lists:seq(1, 40)]),
  325. ResponsePacket =
  326. "HTTP/1.0 302 Found\r
  327. Location: http://www.google.co.il/\r
  328. Cache-Control: private\r
  329. Content-Type: text/html; charset=UTF-8\r
  330. 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
  331. Date: Sun, 04 Dec 2011 15:55:01 GMT\r
  332. Server: gws\r
  333. Content-Length: 221\r
  334. X-XSS-Protection: 1; mode=block\r
  335. X-Frame-Options: SAMEORIGIN\r
  336. \r
  337. <HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
  338. <TITLE>302 Moved</TITLE></HEAD><BODY>
  339. <H1>302 Moved</H1>
  340. The document has moved
  341. <A HREF=\"http://www.google.co.il/\">here</A>.
  342. </BODY></HTML>",
  343. Tests = [
  344. {200, ["GET / HTTP/1.0\r\nHost: localhost\r\n"
  345. "Set-Cookie: ", HugeCookie, "\r\n\r\n"]},
  346. {200, "\r\n\r\n\r\n\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  347. {200, "GET http://proxy/ HTTP/1.1\r\nHost: localhost\r\n\r\n"},
  348. {400, "\n"},
  349. {400, "Garbage\r\n\r\n"},
  350. {400, "\r\n\r\n\r\n\r\n\r\n\r\n"},
  351. {400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"},
  352. {400, "GET http://proxy/ HTTP/1.1\r\n\r\n"},
  353. {400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"},
  354. {505, ResponsePacket},
  355. {408, "GET / HTTP/1.1\r\n"},
  356. {408, "GET / HTTP/1.1\r\nHost: localhost"},
  357. {408, "GET / HTTP/1.1\r\nHost: localhost\r\n"},
  358. {408, "GET / HTTP/1.1\r\nHost: localhost\r\n\r"},
  359. {414, Huge},
  360. {400, "GET / HTTP/1.1\r\n" ++ Huge},
  361. {505, "GET / HTTP/1.2\r\nHost: localhost\r\n\r\n"},
  362. {closed, ""},
  363. {closed, "\r\n"},
  364. {closed, "\r\n\r\n"},
  365. {closed, "GET / HTTP/1.1"}
  366. ],
  367. _ = [{Status, Packet} = begin
  368. Ret = quick_raw(Packet, Config),
  369. {Ret, Packet}
  370. end || {Status, Packet} <- Tests].
  371. check_status(Config) ->
  372. Tests = [
  373. {102, "/long_polling"},
  374. {200, "/"},
  375. {200, "/simple"},
  376. {204, "/loop_timeout"},
  377. {400, "/static/%2f"},
  378. {400, "/static/%2e"},
  379. {400, "/static/%2e%2e"},
  380. {403, "/static/test_dir"},
  381. {403, "/static/test_dir/"},
  382. {403, "/static/test_noread"},
  383. {404, "/not/found"},
  384. {404, "/static/not_found"},
  385. {500, "/handler_errors?case=handler_before_reply"},
  386. {500, "/handler_errors?case=init_before_reply"},
  387. {666, "/init_shutdown"}
  388. ],
  389. _ = [{Status, URL} = begin
  390. Ret = quick_get(URL, Config),
  391. {Ret, URL}
  392. end || {Status, URL} <- Tests].
  393. %% @todo Convert to cowboy_client.
  394. chunked_response(Config) ->
  395. {ok, {{"HTTP/1.1", 200, "OK"}, _, "chunked_handler\r\nworks fine!"}}
  396. = httpc:request(binary_to_list(build_url("/chunked_response", Config))).
  397. %% Check if sending requests whose size is around the MTU breaks something.
  398. echo_body(Config) ->
  399. Client = ?config(client, Config),
  400. {ok, [{mtu, MTU}]} = inet:ifget("lo", [mtu]),
  401. [begin
  402. Body = list_to_binary(lists:duplicate(Size, $a)),
  403. {ok, Client2} = cowboy_client:request(<<"POST">>,
  404. build_url("/echo/body", Config),
  405. [{<<"connection">>, <<"close">>}],
  406. Body, Client),
  407. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  408. {ok, Body, _} = cowboy_client:response_body(Client3)
  409. end || Size <- lists:seq(MTU - 500, MTU)].
  410. error_chain_handle_after_reply(Config) ->
  411. Client = ?config(client, Config),
  412. {ok, Client2} = cowboy_client:request(<<"GET">>,
  413. build_url("/", Config), Client),
  414. {ok, Client3} = cowboy_client:request(<<"GET">>,
  415. build_url("/handler_errors?case=handle_after_reply", Config), Client2),
  416. {ok, 200, _, Client4} = cowboy_client:response(Client3),
  417. {ok, 200, _, Client5} = cowboy_client:response(Client4),
  418. {error, closed} = cowboy_client:response(Client5).
  419. error_chain_handle_before_reply(Config) ->
  420. Client = ?config(client, Config),
  421. {ok, Client2} = cowboy_client:request(<<"GET">>,
  422. build_url("/", Config), Client),
  423. {ok, Client3} = cowboy_client:request(<<"GET">>,
  424. build_url("/handler_errors?case=handle_before_reply", Config), Client2),
  425. {ok, 200, _, Client4} = cowboy_client:response(Client3),
  426. {ok, 500, _, Client5} = cowboy_client:response(Client4),
  427. {error, closed} = cowboy_client:response(Client5).
  428. error_handle_after_reply(Config) ->
  429. Client = ?config(client, Config),
  430. {ok, Client2} = cowboy_client:request(<<"GET">>,
  431. build_url("/handler_errors?case=handle_after_reply", Config), Client),
  432. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  433. {error, closed} = cowboy_client:response(Client3).
  434. error_init_after_reply(Config) ->
  435. Client = ?config(client, Config),
  436. {ok, Client2} = cowboy_client:request(<<"GET">>,
  437. build_url("/handler_errors?case=init_after_reply", Config), Client),
  438. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  439. {error, closed} = cowboy_client:response(Client3).
  440. error_init_reply_handle_error(Config) ->
  441. Client = ?config(client, Config),
  442. {ok, Client2} = cowboy_client:request(<<"GET">>,
  443. build_url("/handler_errors?case=init_reply_handle_error", Config), Client),
  444. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  445. {error, closed} = cowboy_client:response(Client3).
  446. headers_dupe(Config) ->
  447. Client = ?config(client, Config),
  448. {ok, Client2} = cowboy_client:request(<<"GET">>,
  449. build_url("/headers/dupe", Config), Client),
  450. {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
  451. {<<"connection">>, <<"close">>}
  452. = lists:keyfind(<<"connection">>, 1, Headers),
  453. Connections = [H || H = {Name, _} <- Headers, Name =:= <<"connection">>],
  454. 1 = length(Connections),
  455. {error, closed} = cowboy_client:response(Client3).
  456. http10_chunkless(Config) ->
  457. Client = ?config(client, Config),
  458. Transport = ?config(transport, Config),
  459. {ok, Client2} = cowboy_client:connect(
  460. Transport, "localhost", ?config(port, Config), Client),
  461. Data = "GET /chunked_response HTTP/1.0\r\nHost: localhost\r\n\r\n",
  462. {ok, Client3} = cowboy_client:raw_request(Data, Client2),
  463. {ok, 200, Headers, Client4} = cowboy_client:response(Client3),
  464. false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
  465. %% Hack: we just try to get 28 bytes and compare.
  466. {ok, Transport, Socket} = cowboy_client:transport(Client4),
  467. Buffer = element(7, Client4),
  468. Buffer2 = case Transport:recv(Socket, 28 - byte_size(Buffer), 1000) of
  469. {ok, Recv} -> << Buffer/binary, Recv/binary >>;
  470. _ -> Buffer
  471. end,
  472. <<"chunked_handler\r\nworks fine!">> = Buffer2.
  473. http10_hostless(Config) ->
  474. Port10 = ?config(port, Config) + 10,
  475. Name = list_to_atom("http10_hostless_" ++ integer_to_list(Port10)),
  476. ranch:start_listener(Name, 5,
  477. ?config(transport, Config), ?config(opts, Config) ++ [{port, Port10}],
  478. cowboy_protocol, [
  479. {env, [{dispatch, [{'_', [
  480. {[<<"http1.0">>, <<"hostless">>], http_handler, []}]}]}]},
  481. {max_keepalive, 50},
  482. {timeout, 500}]
  483. ),
  484. 200 = quick_raw("GET /http1.0/hostless HTTP/1.0\r\n\r\n",
  485. [{port, Port10}|Config]),
  486. cowboy:stop_listener(http10).
  487. keepalive_max(Config) ->
  488. Client = ?config(client, Config),
  489. URL = build_url("/", Config),
  490. ok = keepalive_max_loop(Client, URL, 50).
  491. keepalive_max_loop(_, _, 0) ->
  492. ok;
  493. keepalive_max_loop(Client, URL, N) ->
  494. Headers = [{<<"connection">>, <<"keep-alive">>}],
  495. {ok, Client2} = cowboy_client:request(<<"GET">>, URL, Headers, Client),
  496. {ok, 200, RespHeaders, Client3} = cowboy_client:response(Client2),
  497. Expected = case N of
  498. 1 -> <<"close">>;
  499. N -> <<"keep-alive">>
  500. end,
  501. {<<"connection">>, Expected}
  502. = lists:keyfind(<<"connection">>, 1, RespHeaders),
  503. keepalive_max_loop(Client3, URL, N - 1).
  504. keepalive_nl(Config) ->
  505. Client = ?config(client, Config),
  506. URL = build_url("/", Config),
  507. ok = keepalive_nl_loop(Client, URL, 10).
  508. keepalive_nl_loop(_, _, 0) ->
  509. ok;
  510. keepalive_nl_loop(Client, URL, N) ->
  511. Headers = [{<<"connection">>, <<"keep-alive">>}],
  512. {ok, Client2} = cowboy_client:request(<<"GET">>, URL, Headers, Client),
  513. {ok, 200, RespHeaders, Client3} = cowboy_client:response(Client2),
  514. {<<"connection">>, <<"keep-alive">>}
  515. = lists:keyfind(<<"connection">>, 1, RespHeaders),
  516. {ok, Transport, Socket} = cowboy_client:transport(Client2),
  517. ok = Transport:send(Socket, <<"\r\n">>), %% empty line
  518. keepalive_nl_loop(Client3, URL, N - 1).
  519. multipart(Config) ->
  520. Client = ?config(client, Config),
  521. Body = <<
  522. "This is a preamble."
  523. "\r\n--OHai\r\nX-Name:answer\r\n\r\n42"
  524. "\r\n--OHai\r\nServer:Cowboy\r\n\r\nIt rocks!\r\n"
  525. "\r\n--OHai--"
  526. "This is an epiloque."
  527. >>,
  528. {ok, Client2} = cowboy_client:request(<<"POST">>,
  529. build_url("/multipart", Config),
  530. [{<<"content-type">>, <<"multipart/x-makes-no-sense; boundary=OHai">>}],
  531. Body, Client),
  532. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  533. {ok, RespBody, _} = cowboy_client:response_body(Client3),
  534. Parts = binary_to_term(RespBody),
  535. Parts = [
  536. {[{<<"x-name">>, <<"answer">>}], <<"42">>},
  537. {[{<<"server">>, <<"Cowboy">>}], <<"It rocks!\r\n">>}
  538. ].
  539. nc_reqs(Config, Input) ->
  540. Cat = os:find_executable("cat"),
  541. Nc = os:find_executable("nc"),
  542. case {Cat, Nc} of
  543. {false, _} ->
  544. {skip, {notfound, cat}};
  545. {_, false} ->
  546. {skip, {notfound, nc}};
  547. _Good ->
  548. %% Throw garbage at the server then check if it's still up.
  549. {port, Port} = lists:keyfind(port, 1, Config),
  550. StrPort = integer_to_list(Port),
  551. [os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort)
  552. || _ <- lists:seq(1, 100)],
  553. 200 = quick_get("/", Config)
  554. end.
  555. nc_rand(Config) ->
  556. nc_reqs(Config, "/dev/urandom").
  557. nc_zero(Config) ->
  558. nc_reqs(Config, "/dev/zero").
  559. onrequest(Config) ->
  560. Client = ?config(client, Config),
  561. {ok, Client2} = cowboy_client:request(<<"GET">>,
  562. build_url("/", Config), Client),
  563. {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
  564. {<<"server">>, <<"Serenity">>} = lists:keyfind(<<"server">>, 1, Headers),
  565. {ok, <<"http_handler">>, _} = cowboy_client:response_body(Client3).
  566. onrequest_reply(Config) ->
  567. Client = ?config(client, Config),
  568. {ok, Client2} = cowboy_client:request(<<"GET">>,
  569. build_url("/?reply=1", Config), Client),
  570. {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
  571. {<<"server">>, <<"Cowboy">>} = lists:keyfind(<<"server">>, 1, Headers),
  572. {ok, <<"replied!">>, _} = cowboy_client:response_body(Client3).
  573. %% Hook for the above onrequest tests.
  574. onrequest_hook(Req) ->
  575. case cowboy_req:qs_val(<<"reply">>, Req) of
  576. {undefined, Req2} ->
  577. cowboy_req:set_resp_header(<<"server">>, <<"Serenity">>, Req2);
  578. {_, Req2} ->
  579. {ok, Req3} = cowboy_req:reply(
  580. 200, [], <<"replied!">>, Req2),
  581. Req3
  582. end.
  583. onresponse_crash(Config) ->
  584. Client = ?config(client, Config),
  585. {ok, Client2} = cowboy_client:request(<<"GET">>,
  586. build_url("/handler_errors?case=init_before_reply", Config), Client),
  587. {ok, 777, Headers, _} = cowboy_client:response(Client2),
  588. {<<"x-hook">>, <<"onresponse">>} = lists:keyfind(<<"x-hook">>, 1, Headers).
  589. onresponse_reply(Config) ->
  590. Client = ?config(client, Config),
  591. {ok, Client2} = cowboy_client:request(<<"GET">>,
  592. build_url("/", Config), Client),
  593. {ok, 777, Headers, Client3} = cowboy_client:response(Client2),
  594. {<<"x-hook">>, <<"onresponse">>} = lists:keyfind(<<"x-hook">>, 1, Headers),
  595. %% Make sure we don't get the body initially sent.
  596. {error, closed} = cowboy_client:response_body(Client3).
  597. %% Hook for the above onresponse tests.
  598. onresponse_hook(_, Headers, _, Req) ->
  599. {ok, Req2} = cowboy_req:reply(
  600. <<"777 Lucky">>, [{<<"x-hook">>, <<"onresponse">>}|Headers], Req),
  601. Req2.
  602. pipeline(Config) ->
  603. Client = ?config(client, Config),
  604. {ok, Client2} = cowboy_client:request(<<"GET">>,
  605. build_url("/", Config), Client),
  606. {ok, Client3} = cowboy_client:request(<<"GET">>,
  607. build_url("/", Config), Client2),
  608. {ok, Client4} = cowboy_client:request(<<"GET">>,
  609. build_url("/", Config), Client3),
  610. {ok, Client5} = cowboy_client:request(<<"GET">>,
  611. build_url("/", Config), Client4),
  612. {ok, Client6} = cowboy_client:request(<<"GET">>,
  613. build_url("/", Config), [{<<"connection">>, <<"close">>}], Client5),
  614. {ok, 200, _, Client7} = cowboy_client:response(Client6),
  615. {ok, 200, _, Client8} = cowboy_client:response(Client7),
  616. {ok, 200, _, Client9} = cowboy_client:response(Client8),
  617. {ok, 200, _, Client10} = cowboy_client:response(Client9),
  618. {ok, 200, _, Client11} = cowboy_client:response(Client10),
  619. {error, closed} = cowboy_client:response(Client11).
  620. rest_bad_accept(Config) ->
  621. Client = ?config(client, Config),
  622. {ok, Client2} = cowboy_client:request(<<"GET">>,
  623. build_url("/bad_accept", Config),
  624. [{<<"accept">>, <<"1">>}],
  625. Client),
  626. {ok, 400, _, _} = cowboy_client:response(Client2).
  627. rest_expires(Config) ->
  628. Client = ?config(client, Config),
  629. {ok, Client2} = cowboy_client:request(<<"GET">>,
  630. build_url("/rest_expires", Config), Client),
  631. {ok, 200, RespHeaders, _} = cowboy_client:response(Client2),
  632. {_, Expires} = lists:keyfind(<<"expires">>, 1, RespHeaders),
  633. {_, LastModified} = lists:keyfind(<<"last-modified">>, 1, RespHeaders),
  634. Expires = LastModified = <<"Fri, 21 Sep 2012 22:36:14 GMT">>,
  635. ok.
  636. rest_keepalive(Config) ->
  637. Client = ?config(client, Config),
  638. URL = build_url("/simple", Config),
  639. ok = rest_keepalive_loop(Client, URL, 10).
  640. rest_keepalive_loop(_, _, 0) ->
  641. ok;
  642. rest_keepalive_loop(Client, URL, N) ->
  643. Headers = [{<<"connection">>, <<"keep-alive">>}],
  644. {ok, Client2} = cowboy_client:request(<<"GET">>, URL, Headers, Client),
  645. {ok, 200, RespHeaders, Client3} = cowboy_client:response(Client2),
  646. {<<"connection">>, <<"keep-alive">>}
  647. = lists:keyfind(<<"connection">>, 1, RespHeaders),
  648. rest_keepalive_loop(Client3, URL, N - 1).
  649. rest_keepalive_post(Config) ->
  650. Client = ?config(client, Config),
  651. ok = rest_keepalive_post_loop(Config, Client, forbidden_post, 10).
  652. rest_keepalive_post_loop(_, _, _, 0) ->
  653. ok;
  654. rest_keepalive_post_loop(Config, Client, simple_post, N) ->
  655. Headers = [
  656. {<<"connection">>, <<"keep-alive">>},
  657. {<<"content-type">>, <<"text/plain">>}
  658. ],
  659. {ok, Client2} = cowboy_client:request(<<"POST">>,
  660. build_url("/simple_post", Config), Headers, "12345", Client),
  661. {ok, 303, RespHeaders, Client3} = cowboy_client:response(Client2),
  662. {<<"connection">>, <<"keep-alive">>}
  663. = lists:keyfind(<<"connection">>, 1, RespHeaders),
  664. rest_keepalive_post_loop(Config, Client3, forbidden_post, N - 1);
  665. rest_keepalive_post_loop(Config, Client, forbidden_post, N) ->
  666. Headers = [
  667. {<<"connection">>, <<"keep-alive">>},
  668. {<<"content-type">>, <<"text/plain">>}
  669. ],
  670. {ok, Client2} = cowboy_client:request(<<"POST">>,
  671. build_url("/forbidden_post", Config), Headers, "12345", Client),
  672. {ok, 403, RespHeaders, Client3} = cowboy_client:response(Client2),
  673. {<<"connection">>, <<"keep-alive">>}
  674. = lists:keyfind(<<"connection">>, 1, RespHeaders),
  675. rest_keepalive_post_loop(Config, Client3, simple_post, N - 1).
  676. rest_missing_get_callbacks(Config) ->
  677. Client = ?config(client, Config),
  678. {ok, Client2} = cowboy_client:request(<<"GET">>,
  679. build_url("/missing_get_callbacks", Config), Client),
  680. {ok, 500, _, _} = cowboy_client:response(Client2).
  681. rest_missing_put_callbacks(Config) ->
  682. Client = ?config(client, Config),
  683. {ok, Client2} = cowboy_client:request(<<"PUT">>,
  684. build_url("/missing_put_callbacks", Config),
  685. [{<<"content-type">>, <<"application/json">>}],
  686. <<"{}">>, Client),
  687. {ok, 500, _, _} = cowboy_client:response(Client2).
  688. rest_nodelete(Config) ->
  689. Client = ?config(client, Config),
  690. {ok, Client2} = cowboy_client:request(<<"DELETE">>,
  691. build_url("/nodelete", Config), Client),
  692. {ok, 500, _, _} = cowboy_client:response(Client2).
  693. rest_resource_get_etag(Config, Type) ->
  694. rest_resource_get_etag(Config, Type, []).
  695. rest_resource_get_etag(Config, Type, Headers) ->
  696. Client = ?config(client, Config),
  697. {ok, Client2} = cowboy_client:request(<<"GET">>,
  698. build_url("/resetags?type=" ++ Type, Config), Headers, Client),
  699. {ok, Status, RespHeaders, _} = cowboy_client:response(Client2),
  700. case lists:keyfind(<<"etag">>, 1, RespHeaders) of
  701. false -> {Status, false};
  702. {<<"etag">>, ETag} -> {Status, ETag}
  703. end.
  704. rest_resource_etags(Config) ->
  705. Tests = [
  706. {200, <<"W/\"etag-header-value\"">>, "tuple-weak"},
  707. {200, <<"\"etag-header-value\"">>, "tuple-strong"},
  708. {200, <<"W/\"etag-header-value\"">>, "binary-weak-quoted"},
  709. {200, <<"\"etag-header-value\"">>, "binary-strong-quoted"},
  710. {500, false, "binary-strong-unquoted"},
  711. {500, false, "binary-weak-unquoted"}
  712. ],
  713. _ = [{Status, ETag, Type} = begin
  714. {Ret, RespETag} = rest_resource_get_etag(Config, Type),
  715. {Ret, RespETag, Type}
  716. end || {Status, ETag, Type} <- Tests].
  717. rest_resource_etags_if_none_match(Config) ->
  718. Tests = [
  719. {304, <<"W/\"etag-header-value\"">>, "tuple-weak"},
  720. {304, <<"\"etag-header-value\"">>, "tuple-strong"},
  721. {304, <<"W/\"etag-header-value\"">>, "binary-weak-quoted"},
  722. {304, <<"\"etag-header-value\"">>, "binary-strong-quoted"}
  723. ],
  724. _ = [{Status, Type} = begin
  725. {Ret, _} = rest_resource_get_etag(Config, Type,
  726. [{<<"if-none-match">>, ETag}]),
  727. {Ret, Type}
  728. end || {Status, ETag, Type} <- Tests].
  729. set_resp_body(Config) ->
  730. Client = ?config(client, Config),
  731. {ok, Client2} = cowboy_client:request(<<"GET">>,
  732. build_url("/set_resp/body", Config), Client),
  733. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  734. {ok, <<"A flameless dance does not equal a cycle">>, _}
  735. = cowboy_client:response_body(Client3).
  736. set_resp_header(Config) ->
  737. Client = ?config(client, Config),
  738. {ok, Client2} = cowboy_client:request(<<"GET">>,
  739. build_url("/set_resp/header", Config), Client),
  740. {ok, 200, Headers, _} = cowboy_client:response(Client2),
  741. {<<"vary">>, <<"Accept">>} = lists:keyfind(<<"vary">>, 1, Headers),
  742. {<<"set-cookie">>, _} = lists:keyfind(<<"set-cookie">>, 1, Headers).
  743. set_resp_overwrite(Config) ->
  744. Client = ?config(client, Config),
  745. {ok, Client2} = cowboy_client:request(<<"GET">>,
  746. build_url("/set_resp/overwrite", Config), Client),
  747. {ok, 200, Headers, _} = cowboy_client:response(Client2),
  748. {<<"server">>, <<"DesireDrive/1.0">>}
  749. = lists:keyfind(<<"server">>, 1, Headers).
  750. static_attribute_etag(Config) ->
  751. Client = ?config(client, Config),
  752. {ok, Client2} = cowboy_client:request(<<"GET">>,
  753. build_url("/static_attribute_etag/test.html", Config), Client),
  754. {ok, Client3} = cowboy_client:request(<<"GET">>,
  755. build_url("/static_attribute_etag/test.html", Config), Client2),
  756. {ok, 200, Headers1, Client4} = cowboy_client:response(Client3),
  757. {ok, 200, Headers2, _} = cowboy_client:response(Client4),
  758. {<<"etag">>, ETag1} = lists:keyfind(<<"etag">>, 1, Headers1),
  759. {<<"etag">>, ETag2} = lists:keyfind(<<"etag">>, 1, Headers2),
  760. false = ETag1 =:= undefined,
  761. ETag1 = ETag2.
  762. static_function_etag(Config) ->
  763. Client = ?config(client, Config),
  764. {ok, Client2} = cowboy_client:request(<<"GET">>,
  765. build_url("/static_function_etag/test.html", Config), Client),
  766. {ok, Client3} = cowboy_client:request(<<"GET">>,
  767. build_url("/static_function_etag/test.html", Config), Client2),
  768. {ok, 200, Headers1, Client4} = cowboy_client:response(Client3),
  769. {ok, 200, Headers2, _} = cowboy_client:response(Client4),
  770. {<<"etag">>, ETag1} = lists:keyfind(<<"etag">>, 1, Headers1),
  771. {<<"etag">>, ETag2} = lists:keyfind(<<"etag">>, 1, Headers2),
  772. false = ETag1 =:= undefined,
  773. ETag1 = ETag2.
  774. %% Callback function for generating the ETag for the above test.
  775. static_function_etag(Arguments, etag_data) ->
  776. {_, Filepath} = lists:keyfind(filepath, 1, Arguments),
  777. {_, _Filesize} = lists:keyfind(filesize, 1, Arguments),
  778. {_, _INode} = lists:keyfind(inode, 1, Arguments),
  779. {_, _Modified} = lists:keyfind(mtime, 1, Arguments),
  780. ChecksumCommand = lists:flatten(io_lib:format("sha1sum ~s", [Filepath])),
  781. [Checksum|_] = string:tokens(os:cmd(ChecksumCommand), " "),
  782. {strong, iolist_to_binary(Checksum)}.
  783. static_mimetypes_function(Config) ->
  784. Client = ?config(client, Config),
  785. {ok, Client2} = cowboy_client:request(<<"GET">>,
  786. build_url("/static_mimetypes_function/test.html", Config), Client),
  787. {ok, 200, Headers, _} = cowboy_client:response(Client2),
  788. {<<"content-type">>, <<"text/html">>}
  789. = lists:keyfind(<<"content-type">>, 1, Headers).
  790. static_specify_file(Config) ->
  791. Client = ?config(client, Config),
  792. {ok, Client2} = cowboy_client:request(<<"GET">>,
  793. build_url("/static_specify_file", Config), Client),
  794. {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
  795. {<<"content-type">>, <<"text/css">>}
  796. = lists:keyfind(<<"content-type">>, 1, Headers),
  797. {ok, <<"test_file.css\n">>, _} = cowboy_client:response_body(Client3).
  798. static_specify_file_catchall(Config) ->
  799. Client = ?config(client, Config),
  800. {ok, Client2} = cowboy_client:request(<<"GET">>,
  801. build_url("/static_specify_file/none", Config), Client),
  802. {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
  803. {<<"content-type">>, <<"text/css">>}
  804. = lists:keyfind(<<"content-type">>, 1, Headers),
  805. {ok, <<"test_file.css\n">>, _} = cowboy_client:response_body(Client3).
  806. static_test_file(Config) ->
  807. Client = ?config(client, Config),
  808. {ok, Client2} = cowboy_client:request(<<"GET">>,
  809. build_url("/static/test_file", Config), Client),
  810. {ok, 200, Headers, _} = cowboy_client:response(Client2),
  811. {<<"content-type">>, <<"application/octet-stream">>}
  812. = lists:keyfind(<<"content-type">>, 1, Headers).
  813. static_test_file_css(Config) ->
  814. Client = ?config(client, Config),
  815. {ok, Client2} = cowboy_client:request(<<"GET">>,
  816. build_url("/static/test_file.css", Config), Client),
  817. {ok, 200, Headers, _} = cowboy_client:response(Client2),
  818. {<<"content-type">>, <<"text/css">>}
  819. = lists:keyfind(<<"content-type">>, 1, Headers).
  820. stream_body_set_resp(Config) ->
  821. Client = ?config(client, Config),
  822. {ok, Client2} = cowboy_client:request(<<"GET">>,
  823. build_url("/stream_body/set_resp", Config), Client),
  824. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  825. {ok, <<"stream_body_set_resp">>, _}
  826. = cowboy_client:response_body(Client3).
  827. stream_body_set_resp_close(Config) ->
  828. Client = ?config(client, Config),
  829. {ok, Client2} = cowboy_client:request(<<"GET">>,
  830. build_url("/stream_body/set_resp_close", Config), Client),
  831. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  832. {ok, Transport, Socket} = cowboy_client:transport(Client3),
  833. case element(7, Client3) of
  834. <<"stream_body_set_resp_close">> ->
  835. ok;
  836. Buffer ->
  837. {ok, Rest} = Transport:recv(Socket, 26 - size(Buffer), 1000),
  838. <<"stream_body_set_resp_close">> = << Buffer/binary, Rest/binary >>,
  839. ok
  840. end,
  841. {error, closed} = Transport:recv(Socket, 0, 1000).
  842. te_chunked(Config) ->
  843. Client = ?config(client, Config),
  844. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  845. Chunks = body_to_chunks(50, Body, []),
  846. {ok, Client2} = cowboy_client:request(<<"GET">>,
  847. build_url("/echo/body", Config),
  848. [{<<"transfer-encoding">>, <<"chunked">>}],
  849. Chunks, Client),
  850. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  851. {ok, Body, _} = cowboy_client:response_body(Client3).
  852. te_chunked_delayed(Config) ->
  853. Client = ?config(client, Config),
  854. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  855. Chunks = body_to_chunks(50, Body, []),
  856. {ok, Client2} = cowboy_client:request(<<"GET">>,
  857. build_url("/echo/body", Config),
  858. [{<<"transfer-encoding">>, <<"chunked">>}], Client),
  859. {ok, Transport, Socket} = cowboy_client:transport(Client2),
  860. _ = [begin
  861. ok = Transport:send(Socket, Chunk),
  862. ok = timer:sleep(10)
  863. end || Chunk <- Chunks],
  864. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  865. {ok, Body, _} = cowboy_client:response_body(Client3).
  866. te_identity(Config) ->
  867. Client = ?config(client, Config),
  868. Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
  869. {ok, Client2} = cowboy_client:request(<<"GET">>,
  870. build_url("/echo/body", Config), [], Body, Client),
  871. {ok, 200, _, Client3} = cowboy_client:response(Client2),
  872. {ok, Body, _} = cowboy_client:response_body(Client3).