mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Use gun:info instead of hacks for test socket operations
This commit is contained in:
parent
4493afbba0
commit
3c8e6cf819
2 changed files with 21 additions and 12 deletions
|
@ -42,8 +42,7 @@ idle_timeout_infinity(Config) ->
|
|||
Port = ranch:get_port(name()),
|
||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||
_ = gun:post(ConnPid, "/echo/read_body", [], <<"TEST">>),
|
||||
%% @todo Gun should have a debug function to retrieve the socket.
|
||||
Socket = element(11, element(2, sys:get_state(ConnPid))),
|
||||
#{socket := Socket} = gun:info(ConnPid),
|
||||
Pid = get_remote_pid_tcp(Socket),
|
||||
Ref = erlang:monitor(process, Pid),
|
||||
receive
|
||||
|
@ -61,8 +60,7 @@ request_timeout_infinity(Config) ->
|
|||
}),
|
||||
Port = ranch:get_port(name()),
|
||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||
%% @todo Gun should have a debug function to retrieve the socket.
|
||||
Socket = element(11, element(2, sys:get_state(ConnPid))),
|
||||
#{socket := Socket} = gun:info(ConnPid),
|
||||
Pid = get_remote_pid_tcp(Socket),
|
||||
Ref = erlang:monitor(process, Pid),
|
||||
receive
|
||||
|
|
|
@ -233,7 +233,7 @@ keepalive_nl(Config) ->
|
|||
ConnPid = gun_open(Config),
|
||||
Refs = [begin
|
||||
Ref = gun:get(ConnPid, "/", [{<<"connection">>, <<"keep-alive">>}]),
|
||||
gun:dbg_send_raw(ConnPid, <<"\r\n">>),
|
||||
dbg_send_raw(ConnPid, <<"\r\n">>),
|
||||
Ref
|
||||
end || _ <- lists:seq(1, 10)],
|
||||
_ = [begin
|
||||
|
@ -538,7 +538,7 @@ te_chunked_chopped(Config) ->
|
|||
Ref = gun:post(ConnPid, "/echo/body",
|
||||
[{<<"content-type">>, <<"text/plain">>}]),
|
||||
_ = [begin
|
||||
ok = gun:dbg_send_raw(ConnPid, << C >>),
|
||||
ok = dbg_send_raw(ConnPid, << C >>),
|
||||
receive after 10 -> ok end
|
||||
end || << C >> <= Body2],
|
||||
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
|
||||
|
@ -552,7 +552,7 @@ te_chunked_delayed(Config) ->
|
|||
Ref = gun:post(ConnPid, "/echo/body",
|
||||
[{<<"content-type">>, <<"text/plain">>}]),
|
||||
_ = [begin
|
||||
ok = gun:dbg_send_raw(ConnPid, Chunk),
|
||||
ok = dbg_send_raw(ConnPid, Chunk),
|
||||
receive after 10 -> ok end
|
||||
end || Chunk <- Chunks],
|
||||
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
|
||||
|
@ -568,15 +568,15 @@ te_chunked_split_body(Config) ->
|
|||
_ = [begin
|
||||
case Chunk of
|
||||
<<"0\r\n\r\n">> ->
|
||||
ok = gun:dbg_send_raw(ConnPid, Chunk);
|
||||
ok = dbg_send_raw(ConnPid, Chunk);
|
||||
_ ->
|
||||
[Size, ChunkBody, <<>>] =
|
||||
binary:split(Chunk, [<<"\r\n">>], [global]),
|
||||
PartASize = random:uniform(byte_size(ChunkBody)),
|
||||
<<PartA:PartASize/binary, PartB/binary>> = ChunkBody,
|
||||
ok = gun:dbg_send_raw(ConnPid, [Size, <<"\r\n">>, PartA]),
|
||||
ok = dbg_send_raw(ConnPid, [Size, <<"\r\n">>, PartA]),
|
||||
receive after 10 -> ok end,
|
||||
ok = gun:dbg_send_raw(ConnPid, [PartB, <<"\r\n">>])
|
||||
ok = dbg_send_raw(ConnPid, [PartB, <<"\r\n">>])
|
||||
end
|
||||
end || Chunk <- Chunks],
|
||||
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
|
||||
|
@ -593,9 +593,9 @@ te_chunked_split_crlf(Config) ->
|
|||
%% Split in the newline just before the end of the chunk.
|
||||
Len = byte_size(Chunk) - (random:uniform(2) - 1),
|
||||
<< Chunk2:Len/binary, End/binary >> = Chunk,
|
||||
ok = gun:dbg_send_raw(ConnPid, Chunk2),
|
||||
ok = dbg_send_raw(ConnPid, Chunk2),
|
||||
receive after 10 -> ok end,
|
||||
ok = gun:dbg_send_raw(ConnPid, End)
|
||||
ok = dbg_send_raw(ConnPid, End)
|
||||
end || Chunk <- Chunks],
|
||||
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
|
||||
{ok, Body} = gun:await_body(ConnPid, Ref),
|
||||
|
@ -608,3 +608,14 @@ te_identity(Config) ->
|
|||
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
|
||||
{ok, Body} = gun:await_body(ConnPid, Ref),
|
||||
ok.
|
||||
|
||||
dbg_send_raw(ConnPid, Data) ->
|
||||
#{
|
||||
socket := Socket,
|
||||
transport := Transport
|
||||
} = gun:info(ConnPid),
|
||||
_ = case Transport of
|
||||
tcp -> gen_tcp:send(Socket, Data);
|
||||
tls -> ssl:send(Socket, Data)
|
||||
end,
|
||||
ok.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue