Echo back GET request details similar to httpbin.org/get.
(scope: dict[str, Any], _receive: Receive, send: Send)
| 344 | |
| 345 | |
| 346 | async def get_echo(scope: dict[str, Any], _receive: Receive, send: Send) -> None: |
| 347 | """Echo back GET request details similar to httpbin.org/get.""" |
| 348 | path = scope.get('path', '') |
| 349 | query_string = scope.get('query_string', b'') |
| 350 | args = get_query_params(query_string) |
| 351 | headers = get_headers_dict(scope) |
| 352 | |
| 353 | origin = scope.get('client', ('unknown', 0))[0] |
| 354 | |
| 355 | host = headers.get('host', 'localhost') |
| 356 | scheme = headers.get('x-forwarded-proto', 'http') |
| 357 | url = f'{scheme}://{host}{path}' |
| 358 | if query_string: |
| 359 | url += f'?{query_string}' |
| 360 | |
| 361 | response = { |
| 362 | 'args': args, |
| 363 | 'headers': headers, |
| 364 | 'origin': origin, |
| 365 | 'url': url, |
| 366 | } |
| 367 | |
| 368 | await send_json_response(send, response) |
| 369 | |
| 370 | |
| 371 | async def set_complex_cookies(_scope: dict[str, Any], _receive: Receive, send: Send) -> None: |
nothing calls this directly
no test coverage detected