Skip to content

Commit 71a679f

Browse files
committed
Silence TLS notice logs
1 parent 09951e5 commit 71a679f

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Now uses `Plug.Conn.resp/3` instead of `Plug.Conn.send_resp/3` to prevent controlling process issue in Bandit
44
- Silenced Bandit logs
5+
- Silence TLS notice logs
56

67
## v0.1.10 (2023-02-22)
78

lib/test_server/http_server/bandit.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ defmodule TestServer.HTTPServer.Bandit do
99

1010
@impl TestServer.HTTPServer
1111
def start(instance, port, scheme, options, bandit_options) do
12-
opts = [options[:ipfamily]] ++ options[:tls]
12+
transport_options =
13+
bandit_options
14+
|> Keyword.get(:transport_options, [])
15+
|> put_tls_options(scheme, options[:tls])
1316

1417
thousand_islands_options =
1518
bandit_options
1619
|> Keyword.get(:options, [])
1720
|> Keyword.put(:port, port)
18-
|> Keyword.update(:transport_options, opts, & &1 ++ opts)
21+
|> Keyword.put(:transport_options, [options[:ipfamily]] ++ transport_options)
1922

2023
bandit_options =
2124
bandit_options
@@ -30,6 +33,12 @@ defmodule TestServer.HTTPServer.Bandit do
3033
end
3134
end
3235

36+
defp put_tls_options(transport_options, :http, _tls_options), do: transport_options
37+
38+
defp put_tls_options(transport_options, :https, tls_options) do
39+
Keyword.merge(transport_options, Keyword.put_new(tls_options, :log_level, :warning))
40+
end
41+
3342
@impl TestServer.HTTPServer
3443
def stop(server_pid, _bandit_options) do
3544
ThousandIsland.stop(server_pid)

lib/test_server/http_server/httpd.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ defmodule TestServer.HTTPServer.Httpd do
2626
defp put_tls_options(httpd_options, :http, _tls_options), do: httpd_options
2727

2828
defp put_tls_options(httpd_options, :https, tls_options) do
29+
tls_options = Keyword.put_new(tls_options, :log_level, :warning)
30+
2931
Keyword.put(httpd_options, :socket_type, {:ssl, tls_options})
3032
end
3133

lib/test_server/http_server/plug_cowboy.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule TestServer.HTTPServer.Plug.Cowboy do
2424
|> Keyword.put(:dispatch, dispatch(instance))
2525
|> Keyword.put(:ref, cowboy_ref(port))
2626
|> Keyword.put(:net, options[:ipfamily])
27-
|> Keyword.merge(options[:tls])
27+
|> put_tls_options(scheme, options[:tls])
2828

2929
case apply(Cowboy, scheme, [TestServer.Plug, {__MODULE__, %{}, instance}, cowboy_options]) do
3030
{:ok, pid} -> {:ok, pid, cowboy_options}
@@ -38,6 +38,12 @@ defmodule TestServer.HTTPServer.Plug.Cowboy do
3838
[{:_, dispatches}]
3939
end
4040

41+
defp put_tls_options(cowboy_options, :http, _tls_options), do: cowboy_options
42+
43+
defp put_tls_options(cowboy_options, :https, tls_options) do
44+
Keyword.merge(cowboy_options, Keyword.put_new(tls_options, :log_level, :warning))
45+
end
46+
4147
@impl TestServer.HTTPServer
4248
def stop(_pid, cowboy_options) do
4349
port = Keyword.fetch!(cowboy_options, :port)

test/test_server_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ defmodule TestServerTest do
5656
verify_fun: {&:ssl_verify_hostname.verify_fun/3, check_hostname: 'localhost'},
5757
customize_hostname_check: [
5858
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
59-
]
60-
]
59+
],
60+
log_level: :warning
61+
],
6162
]
6263
end
6364

0 commit comments

Comments
 (0)