Skip to content

RuntimeError with Uvicorn (invalid Content-Length) #187

@medihack

Description

@medihack

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions