| 146 | return {"type": "http.request", "body": body, "more_body": True} |
| 147 | |
| 148 | async def send(message: typing.MutableMapping[str, typing.Any]) -> None: |
| 149 | nonlocal status_code, response_headers, response_started |
| 150 | |
| 151 | if message["type"] == "http.response.start": |
| 152 | assert not response_started |
| 153 | |
| 154 | status_code = message["status"] |
| 155 | response_headers = message.get("headers", []) |
| 156 | response_started = True |
| 157 | |
| 158 | elif message["type"] == "http.response.body": |
| 159 | assert not response_complete.is_set() |
| 160 | body = message.get("body", b"") |
| 161 | more_body = message.get("more_body", False) |
| 162 | |
| 163 | if body and request.method != "HEAD": |
| 164 | body_parts.append(body) |
| 165 | |
| 166 | if not more_body: |
| 167 | response_complete.set() |
| 168 | |
| 169 | try: |
| 170 | await self.app(scope, receive, send) |