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):