From 23ad25655d9cce2edc9cba39ec3cb0314f31d382 Mon Sep 17 00:00:00 2001 From: Mat Trudel Date: Fri, 10 May 2024 15:39:31 -0400 Subject: [PATCH] =?UTF-8?q?Improve=20pdict=20clearing=20based=20on=20Jos?= =?UTF-8?q?=C3=A9's=20suggestion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bandit/http1/handler.ex | 9 ++------- test/bandit/http1/request_test.exs | 5 +---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/bandit/http1/handler.ex b/lib/bandit/http1/handler.ex index 99dbc56e..8a96a5ec 100644 --- a/lib/bandit/http1/handler.ex +++ b/lib/bandit/http1/handler.ex @@ -22,7 +22,6 @@ defmodule Bandit.HTTP1.Handler do under_limit = request_limit == 0 || requests_processed < request_limit if under_limit && transport.keepalive do - Logger.reset_metadata() if Keyword.get(state.opts.http_1, :clear_process_dict, true), do: clear_process_dict() gc_every_n_requests = Keyword.get(state.opts.http_1, :gc_every_n_keepalive_requests, 5) if rem(requests_processed, gc_every_n_requests) == 0, do: :erlang.garbage_collect() @@ -33,12 +32,8 @@ defmodule Bandit.HTTP1.Handler do end defp clear_process_dict do - Enum.each(Process.get_keys(), fn - key when is_atom(key) -> - if !match?("$" <> _, to_string(key)), do: Process.delete(key) - - key -> - Process.delete(key) + Enum.each(Process.get_keys(), fn key -> + if key not in ~w[$ancestors $initial_call]a, do: Process.delete(key) end) end diff --git a/test/bandit/http1/request_test.exs b/test/bandit/http1/request_test.exs index 28c6a8df..50fbef29 100644 --- a/test/bandit/http1/request_test.exs +++ b/test/bandit/http1/request_test.exs @@ -239,10 +239,7 @@ defmodule HTTP1RequestTest do assert {:ok, "200 OK", _headers, "[]"} = SimpleHTTP1Client.recv_reply(client) SimpleHTTP1Client.send(client, "GET", "/pdict", ["host: localhost"]) - - # Keep one $ value unfiltered to test that we do not clobber those - assert {:ok, "200 OK", _headers, "[\"$logger_metadata$\": %{}]"} = - SimpleHTTP1Client.recv_reply(client) + assert {:ok, "200 OK", _headers, "[]"} = SimpleHTTP1Client.recv_reply(client) end def pdict(conn) do