pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ProxyFixMiddleware throws exception when X-Forwarded-Host is present

npt opened this issue · comments

Using Hypercorn (0.16.0) via Quart (0.19.6), running with quart run.

When I use ProxyFixMiddleware (via app.asgi_app = ProxyFixMiddleware(app.asgi_app)), any request not including the X-Forwarded-Host header works as expected. Any request with X-Forwarded-Host, however, causes this exception:

Traceback (most recent call last):
  File ".../.venv/lib/python3.12/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle
    await app(scope, receive, send, sync_spawn, call_soon)
  File ".../.venv/lib/python3.12/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
    await self.app(scope, receive, send)
  File ".../.venv/lib/python3.12/site-packages/quart/app.py", line 1667, in __call__
    await self.asgi_app(scope, receive, send)
  File ".../.venv/lib/python3.12/site-packages/hypercorn/middleware/proxy_fix.py", line 61, in __call__
    await self.app(scope, receive, send)
  File ".../.venv/lib/python3.12/site-packages/quart/app.py", line 1693, in asgi_app
    await asgi_handler(receive, send)
  File ".../.venv/lib/python3.12/site-packages/quart/asgi.py", line 45, in __call__
    request = self._create_request_from_scope(send)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/quart/asgi.py", line 68, in _create_request_from_scope
    headers.add(name.decode("latin1").title(), value.decode("latin1"))
                                               ^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?

Is fixed in 3fbd5f2 (not yet released)