diff --git a/aws_lambda_powertools/utilities/data_classes/common.py b/aws_lambda_powertools/utilities/data_classes/common.py index 45f6bafc957..c651c225fab 100644 --- a/aws_lambda_powertools/utilities/data_classes/common.py +++ b/aws_lambda_powertools/utilities/data_classes/common.py @@ -32,9 +32,12 @@ def get_header_value( headers: Dict[str, str], name: str, default_value: Optional[str], case_sensitive: Optional[bool] ) -> Optional[str]: """Get header value by name""" + # If headers is NoneType, return default value + if not headers: + return default_value + if case_sensitive: return headers.get(name, default_value) - name_lower = name.lower() return next( diff --git a/tests/functional/event_handler/test_api_gateway.py b/tests/functional/event_handler/test_api_gateway.py index 0c6d1954836..f1fb6a1f942 100644 --- a/tests/functional/event_handler/test_api_gateway.py +++ b/tests/functional/event_handler/test_api_gateway.py @@ -314,6 +314,24 @@ def return_text() -> Response: assert result["body"] == expected_value +def test_compress_no_accept_encoding_null_headers(): + # GIVEN a function with compress=True + # AND the request has no headers + app = ApiGatewayResolver() + expected_value = "Foo" + + @app.get("/my/path", compress=True) + def return_text() -> Response: + return Response(200, content_types.TEXT_PLAIN, expected_value) + + # WHEN calling the event handler + result = app({"path": "/my/path", "httpMethod": "GET", "headers": None}, None) + + # THEN don't perform any gzip compression + assert result["isBase64Encoded"] is False + assert result["body"] == expected_value + + def test_cache_control_200(): # GIVEN a function with cache_control set app = ApiGatewayResolver()