aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/gun.erl b/src/gun.erl
index d5a39af..b1f493b 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -488,14 +488,22 @@ connect(ServerPid, Destination, Headers, ReqOpts) ->
%% Awaiting gun messages.
-%% @todo spec await await_body
-
+-type resp_headers() :: [{binary(), binary()}].
+-type await_result() :: {inform, 100..199, resp_headers()}
+ | {response, fin | nofin, non_neg_integer(), resp_headers()}
+ | {data, fin | nofin, binary()}
+ | {trailers, resp_headers()}
+ | {push, reference(), binary(), binary(), resp_headers()}
+ | {error, {stream_error | connection_error | down, any()} | timeout}.
+
+-spec await(pid(), reference()) -> await_result().
await(ServerPid, StreamRef) ->
MRef = monitor(process, ServerPid),
Res = await(ServerPid, StreamRef, 5000, MRef),
demonitor(MRef, [flush]),
Res.
+-spec await(pid(), reference(), timeout() | reference()) -> await_result().
await(ServerPid, StreamRef, MRef) when is_reference(MRef) ->
await(ServerPid, StreamRef, 5000, MRef);
await(ServerPid, StreamRef, Timeout) ->
@@ -505,6 +513,7 @@ await(ServerPid, StreamRef, Timeout) ->
Res.
%% @todo Add gun_upgrade and gun_ws?
+-spec await(pid(), reference(), timeout(), reference()) -> await_result().
await(ServerPid, StreamRef, Timeout, MRef) ->
receive
{gun_inform, ServerPid, StreamRef, Status, Headers} ->
@@ -527,12 +536,18 @@ await(ServerPid, StreamRef, Timeout, MRef) ->
{error, timeout}
end.
+-type await_body_result() :: {ok, binary()}
+ | {ok, binary(), resp_headers()}
+ | {error, {stream_error | connection_error | down, any()} | timeout}.
+
+-spec await_body(pid(), reference()) -> await_body_result().
await_body(ServerPid, StreamRef) ->
MRef = monitor(process, ServerPid),
Res = await_body(ServerPid, StreamRef, 5000, MRef, <<>>),
demonitor(MRef, [flush]),
Res.
+-spec await_body(pid(), reference(), timeout() | reference()) -> await_body_result().
await_body(ServerPid, StreamRef, MRef) when is_reference(MRef) ->
await_body(ServerPid, StreamRef, 5000, MRef, <<>>);
await_body(ServerPid, StreamRef, Timeout) ->
@@ -541,6 +556,7 @@ await_body(ServerPid, StreamRef, Timeout) ->
demonitor(MRef, [flush]),
Res.
+-spec await_body(pid(), reference(), timeout(), reference()) -> await_body_result().
await_body(ServerPid, StreamRef, Timeout, MRef) ->
await_body(ServerPid, StreamRef, Timeout, MRef, <<>>).
@@ -565,14 +581,14 @@ await_body(ServerPid, StreamRef, Timeout, MRef, Acc) ->
{error, timeout}
end.
--spec await_up(pid()) -> {ok, http | http2} | {error, atom()}.
+-spec await_up(pid()) -> {ok, http | http2} | {error, {down, any()} | timeout}.
await_up(ServerPid) ->
MRef = monitor(process, ServerPid),
Res = await_up(ServerPid, 5000, MRef),
demonitor(MRef, [flush]),
Res.
--spec await_up(pid(), reference() | timeout()) -> {ok, http | http2} | {error, atom()}.
+-spec await_up(pid(), reference() | timeout()) -> {ok, http | http2} | {error, {down, any()} | timeout}.
await_up(ServerPid, MRef) when is_reference(MRef) ->
await_up(ServerPid, 5000, MRef);
await_up(ServerPid, Timeout) ->
@@ -581,7 +597,7 @@ await_up(ServerPid, Timeout) ->
demonitor(MRef, [flush]),
Res.
--spec await_up(pid(), timeout(), reference()) -> {ok, http | http2} | {error, atom()}.
+-spec await_up(pid(), timeout(), reference()) -> {ok, http | http2} | {error, {down, any()} | timeout}.
await_up(ServerPid, Timeout, MRef) ->
receive
{gun_up, ServerPid, Protocol} ->