diff options
author | Loïc Hoguin <[email protected]> | 2019-01-09 18:12:51 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-01-09 18:12:51 +0100 |
commit | 6612610964cabadfcf408e4223a702555a3570cb (patch) | |
tree | 98598c40aa031aba05ddbe79d5858fc573bb7b5a /src/gun.erl | |
parent | ab4878838fafbd453b41d031c9224b2ee8d2d956 (diff) | |
download | gun-6612610964cabadfcf408e4223a702555a3570cb.tar.gz gun-6612610964cabadfcf408e4223a702555a3570cb.tar.bz2 gun-6612610964cabadfcf408e4223a702555a3570cb.zip |
Add function gun:stream_info/2
Diffstat (limited to 'src/gun.erl')
-rw-r--r-- | src/gun.erl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/gun.erl b/src/gun.erl index 75092f1..1fd7e37 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -78,8 +78,9 @@ %% Flushing gun messages. -export([flush/1]). -%% Cancelling a stream. +%% Streams. -export([cancel/2]). +-export([stream_info/2]). %% Websocket. -export([ws_upgrade/2]). @@ -643,6 +644,10 @@ flush_ref(StreamRef) -> cancel(ServerPid, StreamRef) -> gen_statem:cast(ServerPid, {cancel, self(), StreamRef}). +-spec stream_info(pid(), reference()) -> {ok, map() | undefined} | {error, not_connected}. +stream_info(ServerPid, StreamRef) -> + gen_statem:call(ServerPid, {stream_info, StreamRef}). + %% @todo Allow upgrading an HTTP/1.1 connection to HTTP/2. %% http2_upgrade @@ -725,6 +730,8 @@ not_connected(_, {retries, Retries}, {keep_state, State, {state_timeout, Timeout, {retries, Retries - 1}}} end; +not_connected({call, From}, {stream_info, _}, _) -> + {keep_state_and_data, {reply, From, {error, not_connected}}}; not_connected(Type, Event, State) -> handle_common(Type, Event, ?FUNCTION_NAME, State). @@ -843,6 +850,9 @@ connected(cast, {ws_send, ReplyTo, _}, _) -> "Connection needs to be upgraded to Websocket " "before the gun:ws_send/1 function can be used."}}, keep_state_and_data; +connected({call, From}, {stream_info, StreamRef}, + #state{protocol=Protocol, protocol_state=ProtoState}) -> + {keep_state_and_data, {reply, From, Protocol:stream_info(ProtoState, StreamRef)}}; connected(Type, Event, State) -> handle_common(Type, Event, ?FUNCTION_NAME, State). |