MCPcopy Index your code
hub / github.com/zappa/Zappa / _handle_asgi_request_v2

Method _handle_asgi_request_v2

zappa/handler.py:493–533  ·  view source on GitHub ↗

Handle a v2 (HTTP API / Function URL) request via ASGI.

(
        self, event: Dict[str, Any], context: Any, script_name: str, settings: ModuleType
    )

Source from the content-addressed store, hash-verified

491 return environ
492
493 def _handle_asgi_request_v2(
494 self, event: Dict[str, Any], context: Any, script_name: str, settings: ModuleType
495 ) -> Dict[str, Any]:
496 """Handle a v2 (HTTP API / Function URL) request via ASGI."""
497 time_start = datetime.datetime.now()
498
499 handler, scope = self._run_asgi_handler(event, context, script_name, settings)
500
501 response_body = ""
502 response_is_base_64_encoded = False
503 if handler.response_body:
504 response_body, response_is_base_64_encoded = self._process_asgi_response_body(
505 bytes(handler.response_body), handler.response_headers, settings=settings
506 )
507
508 cookies: List[str] = []
509 response_headers: Dict[str, str] = {}
510 for name, value in handler.response_headers:
511 header_name = name.decode("latin-1")
512 header_value = value.decode("latin-1")
513 if header_name.lower() == "set-cookie":
514 cookies.append(header_value)
515 else:
516 if header_name in response_headers:
517 response_headers[header_name] = f"{response_headers[header_name]},{header_value}"
518 else:
519 response_headers[header_name] = header_value
520
521 # Log the request
522 time_end = datetime.datetime.now()
523 delta = time_end - time_start
524 response_time_us = int(delta.total_seconds() * 1_000_000)
525 self._log_asgi_request(scope, handler.status_code, len(handler.response_body), response_time_us)
526
527 return {
528 "cookies": cookies,
529 "isBase64Encoded": response_is_base_64_encoded,
530 "statusCode": handler.status_code,
531 "headers": response_headers,
532 "body": response_body,
533 }
534
535 def _handle_asgi_request_v1(
536 self, event: Dict[str, Any], context: Any, script_name: str, is_elb_context: bool, settings: ModuleType

Callers 1

handlerMethod · 0.95

Calls 3

_run_asgi_handlerMethod · 0.95
_log_asgi_requestMethod · 0.95

Tested by

no test coverage detected