From 3aab5ef99b98f618f701510d76bcf639b915794f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 1 May 2017 21:12:50 +0200 Subject: Add gun:info/1 So far only for getting the socket ip and port on the local side. More values may be added later on. --- src/gun.erl | 7 +++++++ test/gun_SUITE.erl | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/gun.erl b/src/gun.erl index 8267460..173bb2d 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -17,6 +17,7 @@ %% Connection. -export([open/2]). -export([open/3]). +-export([info/1]). -export([close/1]). -export([shutdown/1]). @@ -218,6 +219,12 @@ consider_tracing(ServerPid, #{trace := true}) -> consider_tracing(_, _) -> ok. +-spec info(pid()) -> map(). +info(ServerPid) -> + {_, #state{socket=Socket, transport=Transport}} = sys:get_state(ServerPid), + {ok, {SockIP, SockPort}} = Transport:sockname(Socket), + #{sock_ip => SockIP, sock_port => SockPort}. + -spec close(pid()) -> ok. close(ServerPid) -> supervisor:terminate_child(gun_sup, ServerPid). diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index 505f365..b9706a0 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -75,6 +75,12 @@ gone_reason(_) -> error(timeout) end. +info(_) -> + doc("Get info from the Gun connection."), + {ok, Pid} = gun:open("google.com", 443), + #{sock_ip := _, sock_port := _} = gun:info(Pid), + ok. + reply_to(_) -> doc("The reply_to option allows using a separate process for requests."), do_reply_to(http), -- cgit v1.2.3