|
12 | 12 |
|
13 | 13 | from tests.response import Response |
14 | 14 | from uvicorn import Server |
15 | | -from uvicorn._types import ASGIApplication, ASGIReceiveCallable, ASGISendCallable, Scope |
| 15 | +from uvicorn._types import ASGIApplication, ASGIReceiveCallable, ASGIReceiveEvent, ASGISendCallable, Scope |
16 | 16 | from uvicorn.config import WS_PROTOCOLS, Config |
17 | 17 | from uvicorn.lifespan.off import LifespanOff |
18 | 18 | from uvicorn.lifespan.on import LifespanOn |
@@ -387,6 +387,22 @@ async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable |
387 | 387 | assert b'Body: {"hello": "world"}' in protocol.transport.buffer |
388 | 388 |
|
389 | 389 |
|
| 390 | +async def test_bodyless_request_receive(http_protocol_cls: type[HTTPProtocol]): |
| 391 | + request_message: ASGIReceiveEvent | None = None |
| 392 | + |
| 393 | + async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable): |
| 394 | + nonlocal request_message |
| 395 | + request_message = await receive() |
| 396 | + response = Response(b"", status_code=204) |
| 397 | + await response(scope, receive, send) |
| 398 | + |
| 399 | + protocol = get_connected_protocol(app, http_protocol_cls) |
| 400 | + protocol.data_received(SIMPLE_GET_REQUEST) |
| 401 | + await protocol.loop.run_one() |
| 402 | + |
| 403 | + assert request_message == {"type": "http.request", "body": b"", "more_body": False} |
| 404 | + |
| 405 | + |
390 | 406 | async def test_keepalive(http_protocol_cls: type[HTTPProtocol]): |
391 | 407 | app = Response(b"", status_code=204) |
392 | 408 |
|
|
0 commit comments