0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Remove tests for set_resp_body with a stream fun

This commit is contained in:
Loïc Hoguin 2017-07-12 19:25:56 +02:00
parent ff3915a243
commit cf4d8166f8
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
2 changed files with 0 additions and 68 deletions

View file

@ -111,16 +111,6 @@ init_dispatch(Config) ->
[{headers, #{<<"server">> => <<"DesireDrive/1.0">>}}]},
{"/set_resp/body", http_set_resp,
[{body, <<"A flameless dance does not equal a cycle">>}]},
{"/stream_body/set_resp", http_stream_body,
[{reply, set_resp}, {body, <<"stream_body_set_resp">>}]},
{"/stream_body/set_resp_close",
http_stream_body, [
{reply, set_resp_close},
{body, <<"stream_body_set_resp_close">>}]},
{"/stream_body/set_resp_chunked",
http_stream_body, [
{reply, set_resp_chunked},
{body, [<<"stream_body">>, <<"_set_resp_chunked">>]}]},
{"/static/[...]", cowboy_static,
{dir, config(static_dir, Config)}},
{"/static_mimetypes_function/[...]", cowboy_static,
@ -776,36 +766,6 @@ static_test_file_css(Config) ->
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers),
ok.
stream_body_set_resp(Config) ->
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/stream_body/set_resp"),
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
{ok, <<"stream_body_set_resp">>} = gun:await_body(ConnPid, Ref),
ok.
stream_body_set_resp_close(Config) ->
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/stream_body/set_resp_close"),
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
{ok, <<"stream_body_set_resp_close">>} = gun:await_body(ConnPid, Ref),
gun_down(ConnPid).
stream_body_set_resp_chunked(Config) ->
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/stream_body/set_resp_chunked"),
{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
{ok, <<"stream_body_set_resp_chunked">>} = gun:await_body(ConnPid, Ref),
ok.
stream_body_set_resp_chunked10(Config) ->
ConnPid = gun_open(Config, #{http_opts => #{version => 'HTTP/1.0'}}),
Ref = gun:get(ConnPid, "/stream_body/set_resp_chunked"),
{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
{ok, <<"stream_body_set_resp_chunked">>} = gun:await_body(ConnPid, Ref),
gun_down(ConnPid).
te_chunked(Config) ->
Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
ConnPid = gun_open(Config),

View file

@ -1,28 +0,0 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(http_stream_body).
-export([init/2]).
init(Req, Opts) ->
Body = proplists:get_value(body, Opts, "http_handler_stream_body"),
Reply = proplists:get_value(reply, Opts),
SFun = fun () ->
cowboy_req:send_body(Body, nofin, Req)
end,
Req2 = case Reply of
set_resp ->
SLen = iolist_size(Body),
cowboy_req:set_resp_body({stream, SLen, SFun}, Req);
%% @todo Hmm that one will be sent as chunked now.
%% We need an option to disable chunked.
set_resp_close ->
cowboy_req:set_resp_body({stream, undefined, SFun}, Req);
set_resp_chunked ->
%% Here Body should be a list of chunks, not a binary.
SFun2 = fun () ->
lists:foreach(fun (Data) -> cowboy_req:send_body(Data, nofin, Req) end, Body)
end,
cowboy_req:set_resp_body({stream, undefined, SFun2}, Req)
end,
{ok, cowboy_req:reply(200, Req2), Opts}.