Buckets:
AnonymousSpottedToad/human_verified_bucket / codebase /python /inteliver_inteliver /src /inteliver /utils /middleware.py
| from fastapi import Request | |
| from starlette.middleware.base import BaseHTTPMiddleware | |
| from inteliver.utils.i18n import set_locale | |
| class LanguageMiddleware(BaseHTTPMiddleware): | |
| """ | |
| Middleware for setting the language based on the request headers. | |
| This middleware sets the language of the application based on the Accept-Language header | |
| in the incoming request. It uses the set_locale function from the i18n module to determine | |
| the appropriate language for the request. | |
| Attributes: | |
| None | |
| """ | |
| async def dispatch(self, request: Request, call_next): | |
| """ | |
| Dispatch method to set the language for the request. | |
| This method intercepts incoming requests, sets the language based on the Accept-Language | |
| header, and then passes the request to the next middleware or route handler. | |
| Args: | |
| request (Request): The incoming request. | |
| call_next (Callable): The function to call to proceed to the next middleware or route handler. | |
| Returns: | |
| Response: The response generated by the next middleware or route handler. | |
| """ | |
| await set_locale(request) # Set the language for the request | |
| response = await call_next( | |
| request | |
| ) # Proceed to the next middleware or route handler | |
| return response | |
Xet Storage Details
- Size:
- 1.35 kB
- Xet hash:
- 7bbddc11f08d942a1c4ba6ad46a28d886bdc13c2e37d0f2ece817b2753dad654
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.