MCPcopy Create free account
hub / github.com/dbunt1tled/python-fast-api / dispatch

Method dispatch

src/core/http/middleware/x_api_key_auth.py:22–33  ·  view source on GitHub ↗
(self, request: Request, call_next: RequestResponseEndpoint)

Source from the content-addressed store, hash-verified

20 self.hash_service = hash_service
21
22 async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
23 if not self._is_included_path(request.url.path):
24 return await call_next(request)
25
26 authorization = request.headers.get("X-Api-Key")
27 if not authorization:
28 raise UnauthorizedException(error_no=ErrorNo.AUTHORIZATION_X_API_KEY_EMPTY, message="Unauthorized!")
29
30 if not self.hash_service.verify_x_api_key(key=authorization):
31 raise UnauthorizedException(error_no=ErrorNo.AUTHORIZATION_X_API_KEY_INVALID, message="Unauthorized!")
32
33 return await call_next(request)
34
35 @staticmethod
36 def _is_included_path(path: str) -> bool:

Callers

nothing calls this directly

Calls 3

_is_included_pathMethod · 0.95
verify_x_api_keyMethod · 0.80

Tested by

no test coverage detected