From 45facf44a28eb701ac36c20316ef42f72f6367b7 Mon Sep 17 00:00:00 2001 From: Amar Chand Date: Tue, 21 Feb 2023 10:54:07 +0530 Subject: [PATCH] Adds function get_env --- src/cowboy.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cowboy.erl b/src/cowboy.erl index c4be25bf..d593a83b 100644 --- a/src/cowboy.erl +++ b/src/cowboy.erl @@ -17,7 +17,7 @@ -export([start_clear/3]). -export([start_tls/3]). -export([stop_listener/1]). --export([set_env/3]). +-export([set_env/3, get_env/2]). %% Internal. -export([log/2]). @@ -77,6 +77,12 @@ set_env(Ref, Name, Value) -> Opts2 = maps:put(env, maps:put(Name, Value, Env), Opts), ok = ranch:set_protocol_options(Ref, Opts2). +-spec get_env(Ref :: ranch:ref(), Name :: atom()) -> Value :: any(). +get_env(Ref, Name) -> + Opts = ranch:get_protocol_options(Ref), + Env = maps:get(env, Opts, #{}), + maps:get(Name, Env). + %% Internal. -spec log({log, logger:level(), io:format(), list()}, opts()) -> ok.