django_socio_grpc.middlewares

https://docs.djangoproject.com/en/5.0/topics/http/middleware For now only the call method of a middleware is supported

To use async middlewares, you need to use the correct decorator Here we use the sync_and_async_middleware decorators to declare these middlewares as sync and async compatible

Module Contents

Functions

_close_old_connections

close_old_connections_middleware

This middleware allow to correctly close the db old_connection before and after grpc action to avoid using closed connection. Sync and Async supported.

_log_requests

log_requests_middleware

Simple middleware to print wich request being call before starting the action code. Sync and Async supported.

locale_middleware

Middleware to activate i18n language in django. It will look for an Accept-Language formated metadata in the headers key. metadata = (‘headers’, (‘accept-language’, ‘fr-CH, fr;q=0.9, en;q=0.8, de;’))

auth_without_session_middleware

This middleware is here to replace Django default Authentication Middleware as it look for the user session created by the login django method. This middleware is to use when using other Authenifciation pattern such as Token one.

Data

logger

API

django_socio_grpc.middlewares.logger

‘getLogger(…)’

django_socio_grpc.middlewares._close_old_connections()
django_socio_grpc.middlewares.close_old_connections_middleware(get_response: collections.abc.Callable)

This middleware allow to correctly close the db old_connection before and after grpc action to avoid using closed connection. Sync and Async supported.

django_socio_grpc.middlewares._log_requests(request: django_socio_grpc.services.servicer_proxy.GRPCRequestContainer)
django_socio_grpc.middlewares.log_requests_middleware(get_response: collections.abc.Callable)

Simple middleware to print wich request being call before starting the action code. Sync and Async supported.

django_socio_grpc.middlewares.locale_middleware(get_response: collections.abc.Callable)

Middleware to activate i18n language in django. It will look for an Accept-Language formated metadata in the headers key. metadata = (‘headers’, (‘accept-language’, ‘fr-CH, fr;q=0.9, en;q=0.8, de;’))

django_socio_grpc.middlewares.auth_without_session_middleware(get_response: collections.abc.Callable)

This middleware is here to replace Django default Authentication Middleware as it look for the user session created by the login django method. This middleware is to use when using other Authenifciation pattern such as Token one.

This middleware call the perform_authentication of the service. It should be placed before any other middleware that need context.user. If this middleware is not installed the authentication will still perform but after the execution of all the middleware.