Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update use of reset_time to account for float value #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions slowapi/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from limits.errors import ConfigurationError # type: ignore
from limits.storage import MemoryStorage, storage_from_string # type: ignore
from limits.strategies import STRATEGIES, RateLimiter # type: ignore
from limits.util import WindowStats
from starlette.config import Config
from starlette.datastructures import MutableHeaders
from starlette.requests import Request
Expand Down Expand Up @@ -384,10 +385,10 @@ def _inject_headers(
"parameter `response` must be an instance of starlette.responses.Response"
)
try:
window_stats: Tuple[int, int] = self.limiter.get_window_stats(
window_stats: WindowStats = self.limiter.get_window_stats(
current_limit[0], *current_limit[1]
)
reset_in = 1 + window_stats[0]
reset_in = int(1 + window_stats[0])
response.headers.append(
self._header_mapping[HEADERS.LIMIT], str(current_limit[0].amount)
)
Expand Down Expand Up @@ -440,10 +441,10 @@ def _inject_asgi_headers(
"""
if self.enabled and self._headers_enabled and current_limit is not None:
try:
window_stats: Tuple[int, int] = self.limiter.get_window_stats(
window_stats: WindowStats = self.limiter.get_window_stats(
current_limit[0], *current_limit[1]
)
reset_in = 1 + window_stats[0]
reset_in = int(1 + window_stats[0])
headers[self._header_mapping[HEADERS.LIMIT]] = str(
current_limit[0].amount
)
Expand Down