Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError with Uvicorn (invalid Content-Length) #187

Open
medihack opened this issue Jun 1, 2024 · 2 comments
Open

RuntimeError with Uvicorn (invalid Content-Length) #187

medihack opened this issue Jun 1, 2024 · 2 comments

Comments

@medihack
Copy link

medihack commented Jun 1, 2024

When using django-revproxy with Uvicorn I get the below RuntimeError when trying to access a view inheriting from ProxyView. This is not the case when using Daphne as a server. Uvicorn seems to be very strict with Content-Length. Is there a workaround?

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/channels/routing.py", line 62, in __call__
    return await application(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 170, in __call__
    await self.handle(scope, receive, send)
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 216, in handle
    task.result()
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 195, in process_request
    await self.send_response(response, send)
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 357, in send_response
    await send(
  File "/opt/pysetup/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 526, in send
    raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length
@medihack
Copy link
Author

medihack commented Jun 1, 2024

It seems this is not a problem with Uvicorn. It looks more like Daphne is not so strict (for better or worse). So the question is more why the Content-Length is wrong in the first place. Must it be set at all by the ProxyView?

@medihack medihack changed the title RuntimeError when with Uvicorn RuntimeError when with Uvicorn (invalid Content-Length) Jun 1, 2024
@medihack medihack changed the title RuntimeError when with Uvicorn (invalid Content-Length) RuntimeError with Uvicorn (invalid Content-Length) Jun 1, 2024
@andruten
Copy link
Member

andruten commented Jun 5, 2024

Hi @medihack!

Thanks for posting the issue. There is an open issue, #122, asking for asgi support. I would like to dedicate some time to implement async await in django-revproxy... I'll try to find a spot in the near future...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants