mirror of
https://github.com/laurentS/slowapi.git
synced 2026-03-13 09:10:20 +08:00
Fix type errors
This commit is contained in:
@@ -237,7 +237,7 @@ class Limiter:
|
||||
C.HEADERS_ENABLED, False
|
||||
)
|
||||
self._storage_options.update(self.get_app_config(C.STORAGE_OPTIONS, {}))
|
||||
self._storage: Union[Storage, AsyncStorage] = storage_from_string(
|
||||
self._storage = storage_from_string(
|
||||
self._storage_uri or self.get_app_config(C.STORAGE_URL, "memory://"),
|
||||
**self._storage_options,
|
||||
)
|
||||
@@ -334,7 +334,11 @@ class Limiter:
|
||||
"""
|
||||
Place holder until we find a better way to load config from app
|
||||
"""
|
||||
return self.app_config(key, default=default_value, cast=type(default_value))
|
||||
return (
|
||||
self.app_config(key, default=default_value, cast=type(default_value))
|
||||
if default_value
|
||||
else self.app_config(key, default=default_value)
|
||||
)
|
||||
|
||||
def __should_check_backend(self) -> bool:
|
||||
if self.__check_backend_count > MAX_BACKEND_CHECKS:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from starlette.requests import Request
|
||||
|
||||
|
||||
@@ -11,11 +13,17 @@ def get_ipaddr(request: Request) -> str:
|
||||
if "X_FORWARDED_FOR" in request.headers:
|
||||
return request.headers["X_FORWARDED_FOR"]
|
||||
else:
|
||||
return request.client.host or "127.0.0.1"
|
||||
if not request.client or not request.client.host:
|
||||
return "127.0.0.1"
|
||||
|
||||
return request.client.host
|
||||
|
||||
|
||||
def get_remote_address(request: Request) -> str:
|
||||
"""
|
||||
Returns the ip address for the current request (or 127.0.0.1 if none found)
|
||||
"""
|
||||
return request.client.host or "127.0.0.1"
|
||||
if not request.client or not request.client.host:
|
||||
return "127.0.0.1"
|
||||
|
||||
return request.client.host
|
||||
|
||||
Reference in New Issue
Block a user