From f64ab0b6a683db36ec604c38aea9a9d0587efb8a Mon Sep 17 00:00:00 2001 From: Hicham Berbache <64667100+HichamBerbache@users.noreply.github.com> Date: Wed, 4 Jan 2023 10:43:20 +0100 Subject: [PATCH] replaced the del() method by the pop() method Used the pop method to remove items from the headers dictionary rather than using del on a list comprehension. This avoids the overhead of creating the list comprehension. --- httpbin/helpers.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index b29e1835..fd23dee0 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -131,12 +131,11 @@ def get_headers(hide_env=True): if hide_env and ('show_env' not in request.args): for key in ENV_HEADERS: - try: - del headers[key] - except KeyError: - pass + # Use the pop method to remove items from the headers dictionary + headers.pop(key, None) + + return headers - return CaseInsensitiveDict(headers.items()) def semiflatten(multi):