Context

ASGI request context management.

AsgiContext - ASGI-specific routing context.

Provides access to request, response, and application resources for handlers that need transport-specific functionality.

Note: Most handlers should NOT access context directly. They should receive parameters from the dispatcher and return Python objects. Context access is for special cases like setting cookies or accessing session data.

class genro_asgi.context.AsgiContext(request, app, server)[source]

Bases: RoutingContext

ASGI-specific execution context.

Provides access to HTTP request/response and application resources. Created per-request by the dispatcher and injected into RoutingClass.

request

Current HTTP request.

response

Current HTTP response builder.

app

Application instance handling the request.

server

Server instance.

property app: AsgiApplication

Application instance handling the request.

property avatar: Any

Current user identity (set by auth middleware).

property db: Any

Database connection from request state or app.

property request: BaseRequest

Current HTTP request.

property response: Response

Current HTTP response builder.

property server: AsgiServer

Server instance.

property session: Any

Session data (set by session middleware).