MCPcopy
hub / github.com/benoitc/gunicorn / receive

Method receive

gunicorn/asgi/protocol.py:1570–1611  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1568 body_received = False
1569
1570 async def receive():
1571 nonlocal body_received
1572
1573 # Check if stream is closed or missing
1574 if stream is None or stream.state.name == "CLOSED":
1575 return {"type": "http.disconnect"}
1576
1577 # First call: if body already complete (small requests), return it
1578 if not body_received and stream.request_complete and not stream._body_chunks:
1579 body_received = True
1580 body = stream.get_request_body()
1581 return {
1582 "type": "http.request",
1583 "body": body,
1584 "more_body": False,
1585 }
1586
1587 # Streaming: read next chunk
1588 try:
1589 chunk = await asyncio.wait_for(
1590 stream.read_body_chunk(),
1591 timeout=30.0
1592 )
1593 except asyncio.TimeoutError:
1594 return {"type": "http.disconnect"}
1595
1596 if chunk is None:
1597 body_received = True
1598 return {
1599 "type": "http.request",
1600 "body": b"",
1601 "more_body": False,
1602 }
1603
1604 if stream._body_complete:
1605 body_received = True
1606
1607 return {
1608 "type": "http.request",
1609 "body": chunk,
1610 "more_body": not stream._body_complete,
1611 }
1612
1613 async def send(message):
1614 nonlocal response_started, response_complete, headers_sent

Callers

nothing calls this directly

Calls 2

get_request_bodyMethod · 0.80
read_body_chunkMethod · 0.80

Tested by

no test coverage detected