newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
177 stars 103 forks source link

ASGIBrowserMiddleware does not apply when the headers are not lower cased. #1011

Closed trauty-is-me closed 9 months ago

trauty-is-me commented 10 months ago

Description When attempting to run a server (Django/Daphne in my case), when the content-type header is not in lower case the should_insert_html function returns false.

Reviewing the Commit History this has been in place since ASGI support was introduced.

Refer to: https://asgi.readthedocs.io/en/latest/specs/www.html#http

Header names should be lowercased, but it is not required; servers should preserve header case on a best-effort basis.

Expected Behavior Headers should be case insensitve

trauty-is-me commented 10 months ago

I have been able to monkey patch the code for now to swap out the checks from: if header_name == b"content-type": to if header_name.decode().lower() == "content-type": for all of the header checks.

hmstepanek commented 9 months ago

We will open a PR to fix this issue. Thanks for bringing it to our attention!

hmstepanek commented 9 months ago

This has been fixed v9.40.