From 770c1d249333fe97a39697b48632b85ce93eedee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Thu, 12 May 2022 20:44:56 +0200 Subject: [PATCH 1/3] Add state (current state name) info field in gun:info/1 --- doc/src/manual/gun.info.asciidoc | 5 ++++- src/gun.erl | 5 +++-- test/gun_SUITE.erl | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/src/manual/gun.info.asciidoc b/doc/src/manual/gun.info.asciidoc index e3c19d3a..004c1796 100644 --- a/doc/src/manual/gun.info.asciidoc +++ b/doc/src/manual/gun.info.asciidoc @@ -22,7 +22,10 @@ Info :: #{ origin_host => inet:hostname() | inet:ip_address(), origin_port => inet:port_number(), intermediaries => [Intermediary], - cookie_store => gun_cookies:cookie_store() + cookie_store => gun_cookies:cookie_store(), + state => not_connected | domain_lookup | connecting | + initial_tls_handshake | tls_handshake | connected | + closing } Intermediary :: #{ type => connect | socks5, diff --git a/src/gun.erl b/src/gun.erl index 42bd409f..27442882 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -447,7 +447,7 @@ set_owner(ServerPid, NewOwnerPid) -> -spec info(pid()) -> map(). info(ServerPid) -> - {_, #state{ + {CurrentStateName, #state{ owner=Owner, socket=Socket, transport=Transport, @@ -473,7 +473,8 @@ info(ServerPid) -> origin_host => OriginHost, origin_port => OriginPort, intermediaries => intermediaries_info(Intermediaries, []), - cookie_store => CookieStore + cookie_store => CookieStore, + state => CurrentStateName }, Info = case Socket of undefined -> diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index 00b8eab1..b8e07927 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -172,7 +172,7 @@ info(_) -> {ok, {_, Port}} = inet:sockname(ListenSocket), {ok, Pid} = gun:open("localhost", Port), {ok, _} = gen_tcp:accept(ListenSocket, 5000), - #{sock_ip := _, sock_port := _} = gun:info(Pid), + #{sock_ip := _, sock_port := _, state := connected} = gun:info(Pid), gun:close(Pid). keepalive_infinity(_) -> From 71d96b9672e470b2dc4462d3341a95dbbcc72e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Tue, 26 Sep 2023 11:13:18 +0200 Subject: [PATCH 2/3] Document info field 'state' as atom() --- doc/src/manual/gun.info.asciidoc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/src/manual/gun.info.asciidoc b/doc/src/manual/gun.info.asciidoc index 004c1796..35ae91ed 100644 --- a/doc/src/manual/gun.info.asciidoc +++ b/doc/src/manual/gun.info.asciidoc @@ -23,9 +23,7 @@ Info :: #{ origin_port => inet:port_number(), intermediaries => [Intermediary], cookie_store => gun_cookies:cookie_store(), - state => not_connected | domain_lookup | connecting | - initial_tls_handshake | tls_handshake | connected | - closing + state => atom() } Intermediary :: #{ type => connect | socks5, From 7370ea2a4f98666f14e23baf236aa17974469922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Mon, 2 Oct 2023 15:05:39 +0200 Subject: [PATCH 3/3] Rename field to 'state_name' --- doc/src/manual/gun.info.asciidoc | 2 +- src/gun.erl | 2 +- test/gun_SUITE.erl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/manual/gun.info.asciidoc b/doc/src/manual/gun.info.asciidoc index 35ae91ed..db0916d6 100644 --- a/doc/src/manual/gun.info.asciidoc +++ b/doc/src/manual/gun.info.asciidoc @@ -23,7 +23,7 @@ Info :: #{ origin_port => inet:port_number(), intermediaries => [Intermediary], cookie_store => gun_cookies:cookie_store(), - state => atom() + state_name => atom() } Intermediary :: #{ type => connect | socks5, diff --git a/src/gun.erl b/src/gun.erl index 27442882..317faab7 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -474,7 +474,7 @@ info(ServerPid) -> origin_port => OriginPort, intermediaries => intermediaries_info(Intermediaries, []), cookie_store => CookieStore, - state => CurrentStateName + state_name => CurrentStateName }, Info = case Socket of undefined -> diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index b8e07927..6266df99 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -172,7 +172,7 @@ info(_) -> {ok, {_, Port}} = inet:sockname(ListenSocket), {ok, Pid} = gun:open("localhost", Port), {ok, _} = gen_tcp:accept(ListenSocket, 5000), - #{sock_ip := _, sock_port := _, state := connected} = gun:info(Pid), + #{sock_ip := _, sock_port := _, state_name := connected} = gun:info(Pid), gun:close(Pid). keepalive_infinity(_) ->