Skip to content

Commit

Permalink
Merge branch 'main' into fix-package-capture
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Jun 13, 2024
2 parents e818420 + 44ccef0 commit b9ce4e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion newrelic/api/asgi_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/agent_features/test_asgi_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<html><body><p>RESPONSE</p></body></html>"

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,
Expand All @@ -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"<html><body><p>RESPONSE</p></body></html>"
Expand Down

0 comments on commit b9ce4e1

Please sign in to comment.