From 02fed8a1422c9ca6f33127509eebd244f0a74d3f Mon Sep 17 00:00:00 2001 From: Tony Han Date: Sun, 28 Apr 2019 11:03:31 +0800 Subject: Postpone operations until connected --- src/gun.erl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/gun.erl b/src/gun.erl index a548a5d..bb275f5 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -1061,6 +1061,9 @@ handle_common(cast, Any, _, #state{owner=Owner}) when element(2, Any) =/= Owner element(2, Any) ! {gun_error, self(), {notowner, "Operations are restricted to the owner of the connection."}}, keep_state_and_data; +%% We postpone all HTTP/Websocket operations until we are connected. +handle_common(cast, _, StateName, _) when StateName =/= connected -> + {keep_state_and_data, postpone}; handle_common(Type, Event, StateName, StateData) -> error_logger:error_msg("Unexpected event in state ~p of type ~p:~n~w~n~p~n", [StateName, Type, Event, StateData]), -- cgit v1.2.3