(
self, send: ASGISendCallable, response: ResponseTypes
)
| 119 | pass |
| 120 | |
| 121 | async def _send_response( |
| 122 | self, send: ASGISendCallable, response: ResponseTypes |
| 123 | ) -> None: |
| 124 | await send( |
| 125 | cast( |
| 126 | HTTPResponseStartEvent, |
| 127 | { |
| 128 | "type": "http.response.start", |
| 129 | "status": response.status_code, |
| 130 | "headers": encode_headers(response.headers), |
| 131 | }, |
| 132 | ) |
| 133 | ) |
| 134 | |
| 135 | if isinstance(response, WerkzeugResponse): |
| 136 | for data in response.response: |
| 137 | body = data.encode() if isinstance(data, str) else data |
| 138 | await send( |
| 139 | cast( |
| 140 | HTTPResponseBodyEvent, |
| 141 | {"type": "http.response.body", "body": body, "more_body": True}, |
| 142 | ) |
| 143 | ) |
| 144 | else: |
| 145 | async with response.response as response_body: |
| 146 | async for data in response_body: |
| 147 | body = data.encode() if isinstance(data, str) else data |
| 148 | await send( |
| 149 | cast( |
| 150 | HTTPResponseBodyEvent, |
| 151 | { |
| 152 | "type": "http.response.body", |
| 153 | "body": body, |
| 154 | "more_body": True, |
| 155 | }, |
| 156 | ) |
| 157 | ) |
| 158 | await send( |
| 159 | cast( |
| 160 | HTTPResponseBodyEvent, |
| 161 | {"type": "http.response.body", "body": b"", "more_body": False}, |
| 162 | ) |
| 163 | ) |
| 164 | |
| 165 | async def _send_push_promise( |
| 166 | self, send: ASGISendCallable, path: str, headers: Headers |
no test coverage detected