Skip to content

Commit

Permalink
fix View support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulizer1213 committed Jul 13, 2023
1 parent 7fce396 commit c457098
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions aiohttp_ratelimiter.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: aiohttp-ratelimiter
Version: 4.1.1
Version: 4.1.2
Summary: A simple rate limiter for aiohttp.web
Home-page: https://jgltechnologies.com/aiohttplimiter
Author: George Luca
Expand Down Expand Up @@ -144,7 +144,7 @@ Views Example
@routes.view("/")
class Home(View):
@limiter.limit("1/second")
def get(self: web.Request):
def get(self):
return web.Response(text="hello")
```

Expand Down
8 changes: 5 additions & 3 deletions aiohttplimiter/limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
from limits import parse


def default_keyfunc(request: Union[Request, View]) -> str:
def default_keyfunc(ctx: Union[Request, View]) -> str:
"""
Returns the user's IP
"""
if isinstance(request, View):
request = request.request
if isinstance(ctx, View):
request = ctx.request
else:
request = ctx
ip = request.headers.get(
"X-Forwarded-For") or request.remote or "127.0.0.1"
ip = ip.split(",")[0]
Expand Down
Binary file removed dist/aiohttp-ratelimiter-4.1.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_long_description():
return file.read()


VERSION = "4.1.1"
VERSION = "4.1.2"

classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit c457098

Please sign in to comment.