django_socio_grpc.request_transformer.grpc_internal_proxy

Module Contents

Classes

GRPCInternalProxyContext

Proxy context, provide http1 proxy request object and grpc context object Used principally for request data based mechanisme, example: filtering, middleware, authentication

GRPCInternalProxyResponse

Proxy response, provide http1 response and grpc respone object Used principally to middleware. Not doing anything speciale for now but not crashing when using. Need to be improved if some specific behavior needed, for example injecting some data in the reponse metadata.

ResponseHeadersProxy

Class that allow us to write headers both in grpc metadata and http response to keep compatibility with django system See https://github.com/django/django/blob/main/django/http/response.py#L32 for inspiration

API

class django_socio_grpc.request_transformer.grpc_internal_proxy.GRPCInternalProxyContext

Proxy context, provide http1 proxy request object and grpc context object Used principally for request data based mechanisme, example: filtering, middleware, authentication

grpc_context: grpc.aio.ServicerContext

None

grpc_request: google.protobuf.message.Message

None

grpc_action: str

None

service_class_name: str

None

http_request: django_socio_grpc.request_transformer.socio_internal_request.InternalHttpRequest

None

__post_init__()
__getattr__(attr)
class django_socio_grpc.request_transformer.grpc_internal_proxy.GRPCInternalProxyResponse

Proxy response, provide http1 response and grpc respone object Used principally to middleware. Not doing anything speciale for now but not crashing when using. Need to be improved if some specific behavior needed, for example injecting some data in the reponse metadata.

grpc_response: google.protobuf.message.Message

None

grpc_context: grpc.aio.ServicerContext

None

http_response: django_socio_grpc.request_transformer.socio_internal_response.InternalHttpResponse | None

None

headers: Optional[ResponseHeadersProxy]

None

__post_init__()
__getattr__(attr)

This private method is used to correctly distribute the attribute access between the proxy, th grpc_response and the http_response

__delitem__(header)

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does

__setitem__(key, value)

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does

__getitem__(header)

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does

has_header(header)

Case-insensitive check for a header.

__contains__

None

get(key, default=None)

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does

items()

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does

setdefault(key, value)

Allow to treat GRPCInternalProxyResponse as a dict of headers as django.http.HttpResponse does Set a header unless it has already been set.

__getstate__()

Allow to serialize the object mainly for cache purpose

__repr__()
__setstate__(state)

Allow to deserialize the object mainly for cache purpose. When used in cache, the grpc_context is not set. To be correctly use set_current_context method should be called

set_current_context(grpc_context: grpc.aio.ServicerContext)

This method is used to set the current context to the response object when fetched from cache It also enable the copy of the cache metdata

__aiter__()
async __anext__()

Used to iterate over the proxy to the grpc_response as the http response can’t be iterate over

__iter__()
__next__()

Used to iterate over the proxy to the grpc_response as the http response can’t be iterate over

class django_socio_grpc.request_transformer.grpc_internal_proxy.ResponseHeadersProxy(data)

Bases: django.utils.datastructures.CaseInsensitiveMapping

Class that allow us to write headers both in grpc metadata and http response to keep compatibility with django system See https://github.com/django/django/blob/main/django/http/response.py#L32 for inspiration

Initialization

grpc_context: grpc.aio.ServicerContext | None

None

http_response: django_socio_grpc.request_transformer.socio_internal_response.InternalHttpResponse

None

metadata: dict | None

None

__post_init__()
set_grpc_context(grpc_context: grpc.aio.ServicerContext)

When GRPCInternalProxyResponse is created from cache it doesn’t have a grpc_context. This method is used to set it after the object is created and merge their current metadata with the one cached

setdefault(key, value)
__setitem__(key, value)
__delitem__(header)
__repr__()