django_socio_grpc.request_transformer.socio_internal_request
Module Contents
Classes
Class mocking django.http.HttpRequest to make some django behavior like middleware, filtering, authentication, … still work. |
|
Class allowing specific automatic transformation/matching behavior between HTTP headers format expected by django and gRPC metadata format |
Data
API
- django_socio_grpc.request_transformer.socio_internal_request.logger
‘getLogger(…)’
- class django_socio_grpc.request_transformer.socio_internal_request.InternalHttpRequest(grpc_context: django_socio_grpc.request_transformer.grpc_internal_proxy.GRPCInternalProxyContext, grpc_request: google.protobuf.message.Message, grpc_action: str, service_class_name: str)
Bases:
django.http.request.HttpRequestClass mocking django.http.HttpRequest to make some django behavior like middleware, filtering, authentication, … still work.
Initialization
grpc_context is used to get all the headers and other informations grpc_request is only used for filter and pagination from the request if setted by FILTER_BEHAVIOR or PAGINATION_BEHAVIOR settings. grpc_action is used to populate InternalHttpRequest.method
- HEADERS_KEY
‘headers’
- FILTERS_KEY
‘filters’
- PAGINATION_KEY
‘pagination’
- FILTERS_KEY_IN_REQUEST
‘_filters’
- PAGINATION_KEY_IN_REQUEST
‘_pagination’
- METHOD_MAP
None
- headers()
- get_from_metadata(metadata_key: str) dict[str, str | bytes]
Allow to:
Customise the metadata key used for pagination, filter and headers
override default metadata with some passed in HEADERS metadata key to have custom advanced behavior
- parse_specific_key_from_metadata(metadata_key: str) dict[str, str | bytes]
Allow to Customise the metadata key used for pagination, filter and headers
- get_from_request_struct(grpc_request: google.protobuf.message.Message, struct_field_name: str) dict
- class django_socio_grpc.request_transformer.socio_internal_request.RequestMeta(data)
Bases:
django.utils.datastructures.CaseInsensitiveMappingClass allowing specific automatic transformation/matching behavior between HTTP headers format expected by django and gRPC metadata format
Initialization
- HTTP_PREFIX
None
- __getitem__(key)
As HTTP headers are prefixed by HTTP_ by proxy server or CGI, Django store and retrieve headers with HTTP_ prefix As there is no same rule/restriction in gRPC, we need to check if the key is in the dict without HTTP_ prefix if not existing with
- __setitem__(key, value)
See: https://github.com/django/django/blob/main/django/utils/datastructures.py#L305