Echo back content (plain text or base64) with specified content-type.
(scope: dict[str, Any], _receive: Receive, send: Send)
| 392 | |
| 393 | |
| 394 | async def echo_content(scope: dict[str, Any], _receive: Receive, send: Send) -> None: |
| 395 | """Echo back content (plain text or base64) with specified content-type.""" |
| 396 | query_params = get_query_params(scope.get('query_string', b'')) |
| 397 | |
| 398 | content = query_params.get('content', '') |
| 399 | base64_content = query_params.get('base64', '') |
| 400 | c_type = query_params.get('c_type', 'text/html; charset=utf-8') |
| 401 | |
| 402 | out_content = base64.b64decode(base64_content) if base64_content else content.encode() |
| 403 | |
| 404 | await send( |
| 405 | { |
| 406 | 'type': 'http.response.start', |
| 407 | 'status': 200, |
| 408 | 'headers': [[b'content-type', c_type.encode()]], |
| 409 | } |
| 410 | ) |
| 411 | |
| 412 | await send({'type': 'http.response.body', 'body': out_content}) |
| 413 | |
| 414 | |
| 415 | async def robots_txt(_scope: dict[str, Any], _receive: Receive, send: Send) -> None: |
nothing calls this directly
no test coverage detected