aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/manual/gun.asciidoc6
-rw-r--r--src/gun.erl9
-rw-r--r--test/gun_SUITE.erl8
3 files changed, 22 insertions, 1 deletions
diff --git a/doc/src/manual/gun.asciidoc b/doc/src/manual/gun.asciidoc
index 95ca2ad..3f8d43f 100644
--- a/doc/src/manual/gun.asciidoc
+++ b/doc/src/manual/gun.asciidoc
@@ -208,6 +208,7 @@ opts() :: #{
protocols => [http | http2],
retry => non_neg_integer(),
retry_timeout => pos_integer(),
+ supervise => boolean(),
trace => boolean(),
transport => tcp | tls,
transport_opts => [gen_tcp:connect_option()] | [ssl:connect_option()],
@@ -249,6 +250,11 @@ retry_timeout (5000)::
Time between retries in milliseconds.
+supervise (true)::
+
+Whether the Gun process should be started under the `gun_sup`
+supervisor. Set to `false` to use your own supervisor.
+
trace (false)::
Whether to enable `dbg` tracing of the connection process. Should
diff --git a/src/gun.erl b/src/gun.erl
index d8aa15b..c2054e0 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -111,6 +111,7 @@
protocols => [http | http2],
retry => non_neg_integer(),
retry_timeout => pos_integer(),
+ supervise => boolean(),
trace => boolean(),
transport => tcp | tls | ssl,
transport_opts => [gen_tcp:connect_option()] | [ssl:connect_option()],
@@ -211,7 +212,11 @@ do_open(Host, Port, Opts0) ->
end,
case check_options(maps:to_list(Opts)) of
ok ->
- case supervisor:start_child(gun_sup, [self(), Host, Port, Opts]) of
+ Result = case maps:get(supervise, Opts, true) of
+ true -> supervisor:start_child(gun_sup, [self(), Host, Port, Opts]);
+ false -> start_link(self(), Host, Port, Opts)
+ end,
+ case Result of
OK = {ok, ServerPid} ->
consider_tracing(ServerPid, Opts),
OK;
@@ -260,6 +265,8 @@ check_options([{retry, R}|Opts]) when is_integer(R), R >= 0 ->
check_options(Opts);
check_options([{retry_timeout, T}|Opts]) when is_integer(T), T >= 0 ->
check_options(Opts);
+check_options([{supervise, B}|Opts]) when B =:= true; B =:= false ->
+ check_options(Opts);
check_options([{trace, B}|Opts]) when B =:= true; B =:= false ->
check_options(Opts);
check_options([{transport, T}|Opts]) when T =:= tcp; T =:= tls ->
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index 166089b..2c7b4b8 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -488,6 +488,14 @@ stream_info_http2(_) ->
{error, not_connected} = gun:stream_info(Pid, StreamRef),
gun:close(Pid).
+supervise_false(_) ->
+ doc("The supervise option allows starting without a supervisor."),
+ {ok, _, OriginPort} = init_origin(tcp, http),
+ {ok, Pid} = gun:open("localhost", OriginPort, #{supervise => false}),
+ {ok, http} = gun:await_up(Pid),
+ [] = [P || {_, P, _, _} <- supervisor:which_children(gun_sup), P =:= Pid],
+ ok.
+
transform_header_name(_) ->
doc("The transform_header_name option allows changing the case of header names."),
{ok, ListenSocket} = gen_tcp:listen(0, [binary, {active, false}]),