Skip to content
Merged
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
10 changes: 2 additions & 8 deletions rest_framework/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def get_ident(self, request):
if num_proxies == 0 or xff is None:
return remote_addr
addrs = xff.split(',')
client_addr = addrs[-min(num_proxies, len(xff))]
client_addr = addrs[-min(num_proxies, len(addrs))]
return client_addr.strip()

return xff if xff else remote_addr
return ''.join(xff.split()) if xff else remote_addr

def wait(self):
"""
Expand Down Expand Up @@ -173,12 +173,6 @@ def get_cache_key(self, request, view):
if request.user.is_authenticated():
return None # Only throttle unauthenticated requests.

ident = request.META.get('HTTP_X_FORWARDED_FOR')
if ident is None:
ident = request.META.get('REMOTE_ADDR')
else:
ident = ''.join(ident.split())

return self.cache_format % {
'scope': self.scope,
'ident': self.get_ident(request)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xordoquy note here we weren't using the ident variable

Expand Down