aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_event.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-07-22 16:17:10 +0200
committerLoïc Hoguin <[email protected]>2019-07-22 16:17:10 +0200
commit516933f9dd2722329b3886c495d5242308958fe1 (patch)
tree60b16423184a4db405a65266c326b7944ce42256 /src/gun_event.erl
parent265ece680c53f77d1685434d0636216c94021497 (diff)
downloadgun-516933f9dd2722329b3886c495d5242308958fe1.tar.gz
gun-516933f9dd2722329b3886c495d5242308958fe1.tar.bz2
gun-516933f9dd2722329b3886c495d5242308958fe1.zip
Split domain lookup/connect/TLS handshake and add events
This changes the way we connect to servers entirely. We now have three states when connecting (domain_lookup, connect and tls_handshake when applicable) and as a result three corresponding timeout options. Each state has a start/end event associated and the event data was tweaked to best match each event. Since the TLS handshake is separate, the transport_opts option was also split into two: tcp_opts and tls_opts.
Diffstat (limited to 'src/gun_event.erl')
-rw-r--r--src/gun_event.erl42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/gun_event.erl b/src/gun_event.erl
index 5332568..4716f47 100644
--- a/src/gun_event.erl
+++ b/src/gun_event.erl
@@ -27,22 +27,46 @@
-callback init(init_event(), State) -> State.
-%% connect_start/connect_end.
+%% domain_lookup_start/domain_lookup_end.
--type connect_event() :: #{
+-type domain_lookup_event() :: #{
host := inet:hostname() | inet:ip_address(),
port := inet:port_number(),
- transport := tcp | tls,
- transport_opts := [gen_tcp:connect_option()] | [ssl:connect_option()],
+ tcp_opts := [gen_tcp:connect_option()],
timeout := timeout(),
- socket => inet:socket() | ssl:sslsocket() | pid(),
- protocol => http | http2,
+ lookup_info => gun_tcp:lookup_info(),
+ error => any()
+}.
+
+-callback domain_lookup_start(domain_lookup_event(), State) -> State.
+-callback domain_lookup_end(domain_lookup_event(), State) -> State.
+
+%% connect_start/connect_end.
+
+-type connect_event() :: #{
+ lookup_info := gun_tcp:lookup_info(),
+ timeout := timeout(),
+ socket => inet:socket(),
+ protocol => http | http2, %% Only when transport is tcp.
error => any()
}.
-callback connect_start(connect_event(), State) -> State.
-callback connect_end(connect_event(), State) -> State.
+%% tls_handshake_start/tls_handshake_end.
+
+-type tls_handshake_event() :: #{
+ socket := inet:socket() | ssl:sslsocket(), %% The socket before/after will be different.
+ tls_opts := [ssl:connect_option()],
+ timeout := timeout(),
+ protocol => http | http2,
+ error => any()
+}.
+
+-callback tls_handshake_start(tls_handshake_event(), State) -> State.
+-callback tls_handshake_end(tls_handshake_event(), State) -> State.
+
%% request_start/request_headers.
-type request_start_event() :: #{
@@ -201,16 +225,12 @@
%% terminate.
-type terminate_event() :: #{
- state := not_connected | connected,
+ state := not_connected | domain_lookup | connecting | tls_handshake | connected,
reason := normal | shutdown | {shutdown, any()} | any()
}.
-callback terminate(terminate_event(), State) -> State.
-%% @todo domain_lookup_start
-%% @todo domain_lookup_end
-%% @todo tls_handshake_start
-%% @todo tls_handshake_end
%% @todo origin_changed
%% @todo transport_changed
%% @todo push_promise_start