Skip to content

Commit

Permalink
refactor: review code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolnetto committed Aug 20, 2024
1 parent 12a88f4 commit 3109b48
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions slowapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def get_remote_address(request: Request) -> str:
"""
is_local = not request.client or not request.client.host

return "127.0.0.1" if is_local else request.client.host
if is_local:
return "127.0.0.1"
else:
return request.client.host


def get_ipaddr(request: Request) -> str:
Expand All @@ -18,8 +21,8 @@ def get_ipaddr(request: Request) -> str:
provided by uvicorn's ProxyHeadersMiddleware.
"""
has_forwarded = "X_FORWARDED_FOR" in request.headers
return (
request.headers["X_FORWARDED_FOR"]
if has_forwarded
else get_remote_address(request)
)

if has_forwarded:
return request.headers["X_FORWARDED_FOR"]
else:
return get_remote_address(request)

0 comments on commit 3109b48

Please sign in to comment.