diff --git a/newrelic/api/asgi_application.py b/newrelic/api/asgi_application.py index 475faa7cb..dc2fd5bbf 100644 --- a/newrelic/api/asgi_application.py +++ b/newrelic/api/asgi_application.py @@ -175,7 +175,7 @@ async def send_inject_browser_agent(self, message): try: content_length = int(header_value) - except ValueError: + except (TypeError, ValueError): # Invalid content length results in an abort await self.send_buffered() return diff --git a/tests/agent_features/test_asgi_browser.py b/tests/agent_features/test_asgi_browser.py index 925f186d6..26c0d5670 100644 --- a/tests/agent_features/test_asgi_browser.py +++ b/tests/agent_features/test_asgi_browser.py @@ -653,6 +653,19 @@ async def target_asgi_application_invalid_content_length(scope, receive, send): target_application_invalid_content_length = AsgiTest(target_asgi_application_invalid_content_length) + +@asgi_application() +async def target_asgi_application_no_content_length(scope, receive, send): + output = b"
RESPONSE
" + + response_headers = [(b"content-type", b"text/html; charset=utf-8")] + + await send({"type": "http.response.start", "status": 200, "headers": response_headers}) + await send({"type": "http.response.body", "body": output}) + + +target_application_no_content_length = AsgiTest(target_asgi_application_no_content_length) + _test_html_insertion_invalid_content_length_settings = { "browser_monitoring.enabled": True, "browser_monitoring.auto_instrument": True, @@ -674,6 +687,17 @@ def test_html_insertion_invalid_content_length(): assert b"NREUM.info" not in response.body +@override_application_settings(_test_html_insertion_invalid_content_length_settings) +def test_html_insertion_no_content_length(): + response = target_application_no_content_length.get("/") + assert response.status == 200 + + assert "content-type" in response.headers + + assert b"NREUM HEADER" not in response.body + assert b"NREUM.info" not in response.body + + @asgi_application() async def target_asgi_application_content_encoding(scope, receive, send): output = b"RESPONSE
"