aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_event.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-07-13 17:55:20 +0200
committerLoïc Hoguin <[email protected]>2019-07-13 17:55:20 +0200
commitc7138443995ebd56f061b85e5ee0aebb5c04a00e (patch)
tree823defd10c1e09f30af3f954296cf9b73dfe4b8d /src/gun_event.erl
parent071599cbcd25cd2669e26d23a6e202e0275f191a (diff)
downloadgun-c7138443995ebd56f061b85e5ee0aebb5c04a00e.tar.gz
gun-c7138443995ebd56f061b85e5ee0aebb5c04a00e.tar.bz2
gun-c7138443995ebd56f061b85e5ee0aebb5c04a00e.zip
Add ws_upgrade/protocol_changed events
And ensure that Websocket triggers all the request/response events.
Diffstat (limited to 'src/gun_event.erl')
-rw-r--r--src/gun_event.erl37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/gun_event.erl b/src/gun_event.erl
index 72abe24..9e83cf8 100644
--- a/src/gun_event.erl
+++ b/src/gun_event.erl
@@ -48,7 +48,7 @@
-type request_start_event() :: #{
stream_ref := reference(),
reply_to := pid(),
- function := headers | request,
+ function := headers | request | ws_upgrade,
method := iodata(),
scheme => binary(),
authority := iodata(),
@@ -108,6 +108,38 @@
-callback response_end(response_end_event(), State) -> State.
+%% ws_upgrade.
+%%
+%% This event is a signal that the following request and response
+%% result from a gun:ws_upgrade/2,3,4 call.
+%%
+%% There is no corresponding "end" event. Instead, the success is
+%% indicated by a protocol_changed event following the informational
+%% response.
+
+-type ws_upgrade_event() :: #{
+ stream_ref := reference(),
+ reply_to := pid(),
+ opts := gun:ws_opts()
+}.
+
+-callback ws_upgrade(ws_upgrade_event(), State) -> State.
+
+%% protocol_changed.
+%%
+%% This event can occur either following a successful ws_upgrade
+%% event or following a successful CONNECT request.
+%%
+%% @todo Currently there is only a connection-wide variant of this
+%% event. In the future there will be a stream-wide variant to
+%% support CONNECT and Websocket over HTTP/2.
+
+-type protocol_changed_event() :: #{
+ protocol := http2 | ws
+}.
+
+-callback protocol_changed(protocol_changed_event(), State) -> State.
+
%% disconnect.
-type disconnect_event() :: #{
@@ -131,13 +163,10 @@
%% @todo tls_handshake_end
%% @todo origin_changed
%% @todo transport_changed
-%% @todo protocol_changed
%% @todo push_promise_start
%% @todo push_promise_end
%% @todo cancel_start
%% @todo cancel_end
-%% @todo ws_upgrade_start
-%% @todo ws_upgrade_end
%% @todo ws_frame_read_start
%% @todo ws_frame_read_header
%% @todo ws_frame_read_end