aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-11-12 14:00:41 +0100
committerLoïc Hoguin <[email protected]>2020-11-12 14:00:41 +0100
commit4a58077d5162325fa5723690e58e7364adbcb18c (patch)
tree6f088a7a9b9d1f6b0eacdeb98de1eb5b8032b647 /src
parent1ebad8acf803eb797a6c61f6522ebc3b79f104a1 (diff)
downloadgun-4a58077d5162325fa5723690e58e7364adbcb18c.tar.gz
gun-4a58077d5162325fa5723690e58e7364adbcb18c.tar.bz2
gun-4a58077d5162325fa5723690e58e7364adbcb18c.zip
Replace gun:ws_send/2 with gun:ws_send/3
Switching from /2 to /3 should be easy enough. Also update the documentation about HTTP/2 Websocket support.
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl18
-rw-r--r--src/gun_ws.erl2
2 files changed, 1 insertions, 19 deletions
diff --git a/src/gun.erl b/src/gun.erl
index 97cd3c9..2966910 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -92,7 +92,6 @@
-export([ws_upgrade/2]).
-export([ws_upgrade/3]).
-export([ws_upgrade/4]).
--export([ws_send/2]).
-export([ws_send/3]).
%% Internals.
@@ -930,12 +929,6 @@ ws_upgrade(ServerPid, Path, Headers, Opts0) ->
gen_statem:cast(ServerPid, {ws_upgrade, ReplyTo, StreamRef, Path, normalize_headers(Headers), Opts}),
StreamRef.
-%% @todo ws_send/2 will need to be deprecated in favor of a variant with StreamRef.
-%% But it can be kept for the time being since it can still work for HTTP/1.1 (connected_ws_only).
--spec ws_send(pid(), ws_frame() | [ws_frame()]) -> ok.
-ws_send(ServerPid, Frames) ->
- gen_statem:cast(ServerPid, {ws_send, self(), Frames}).
-
-spec ws_send(pid(), stream_ref(), ws_frame() | [ws_frame()]) -> ok.
ws_send(ServerPid, StreamRef, Frames) ->
gen_statem:cast(ServerPid, {ws_send, self(), StreamRef, Frames}).
@@ -1219,11 +1212,6 @@ connected_ws_only(cast, {ws_send, ReplyTo, StreamRef, Frames}, State=#state{
ProtoState, dereference_stream_ref(StreamRef, State),
ReplyTo, EvHandler, EvHandlerState0),
commands(Commands, State#state{event_handler_state=EvHandlerState});
-connected_ws_only(cast, {ws_send, ReplyTo, Frames}, State=#state{
- protocol=Protocol=gun_ws, protocol_state=ProtoState,
- event_handler=EvHandler, event_handler_state=EvHandlerState0}) ->
- {Commands, EvHandlerState} = Protocol:ws_send(Frames, ProtoState, ReplyTo, EvHandler, EvHandlerState0),
- commands(Commands, State#state{event_handler_state=EvHandlerState});
connected_ws_only(cast, Msg, _)
when element(1, Msg) =:= headers; element(1, Msg) =:= request; element(1, Msg) =:= data;
element(1, Msg) =:= connect; element(1, Msg) =:= ws_upgrade ->
@@ -1309,12 +1297,6 @@ connected(cast, {ws_send, ReplyTo, StreamRef, Frames}, State=#state{
ProtoState, dereference_stream_ref(StreamRef, State),
ReplyTo, EvHandler, EvHandlerState0),
commands(Commands, State#state{event_handler_state=EvHandlerState});
-%% Catch-all for the StreamRef-free variant.
-connected(cast, {ws_send, ReplyTo, _}, _) ->
- ReplyTo ! {gun_error, self(), {badstate,
- "Connection needs to be upgraded to Websocket "
- "before the gun:ws_send/1 function can be used."}},
- keep_state_and_data;
connected(Type, Event, State) ->
handle_common_connected(Type, Event, ?FUNCTION_NAME, State).
diff --git a/src/gun_ws.erl b/src/gun_ws.erl
index a1fdfae..73c0fd7 100644
--- a/src/gun_ws.erl
+++ b/src/gun_ws.erl
@@ -28,7 +28,6 @@
-export([closing/4]).
-export([close/4]).
-export([keepalive/3]).
--export([ws_send/5]).
-export([ws_send/6]).
-export([down/1]).
@@ -343,6 +342,7 @@ ws_send([Frame|Tail], State, ReplyTo, EvHandler, EvHandlerState0) ->
Other
end.
+%% @todo We should probably check the _StreamRef value.
ws_send(Frames, State, _StreamRef, ReplyTo, EvHandler, EvHandlerState) ->
ws_send(Frames, State, ReplyTo, EvHandler, EvHandlerState).