async def test_max_body_size() -> None: middleware = AsyncioWSGIMiddleware(echo_body, max_body_size=4) scope: HTTPScope = { "http_version": "1.1", "asgi": {}, "method": "GET", "headers": [], "path": "/", "root_path": "/", "query_string": b"a=b", "raw_path": b"/", "scheme": "http", "type": "http", "client": ("localhost", 80), "server": None, "extensions": {}, } queue: asyncio.Queue = asyncio.Queue() await queue.put({"type": "http.request", "body": b"abcde"}) messages = [] async def _send(message: dict) -> None: nonlocal messages messages.append(message) await middleware(scope, queue.get, _send) assert messages == [ {"headers": [], "status": 400, "type": "http.response.start"}, {"body": bytearray(b""), "type": "http.response.body"}, ]
async def test_wsgi_asyncio() -> None: middleware = AsyncioWSGIMiddleware(echo_body) scope = { "http_version": "1.1", "method": "GET", "path": "/", "query_string": b"a=b", "raw_path": b"/", "scheme": "http", "type": "http", } queue: asyncio.Queue = asyncio.Queue() await queue.put({"type": "http.request"}) messages = [] async def _send(message: dict) -> None: nonlocal messages messages.append(message) await middleware(scope, queue.get, _send) assert messages == [ { "headers": [(b"content-type", b"text/plain; charset=utf-8"), (b"content-length", b"0")], "status": 200, "type": "http.response.start", }, {"body": bytearray(b""), "type": "http.response.body"}, ]
""" WSGI config for princetonpy project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application from hypercorn.middleware import AsyncioWSGIMiddleware os.environ.setdefault("DJANGO_SETTINGS_MODULE", "princetonpy.settings") wsgi_app = get_wsgi_application() application = AsyncioWSGIMiddleware(wsgi_app)
from hypercorn.middleware import AsyncioWSGIMiddleware import httptest.wsgi as wsgi_app asyncio_app = AsyncioWSGIMiddleware(wsgi_app.application)