mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Fix ident format when using HTTP_X_FORWARDED_FOR
If NUM_PROXIES setting is set to None, HTTP_X_FORWARDED_FOR might be used as is, which might contain spaces and cause errors on cache backends like memcached.
This commit is contained in:
parent
e9ac1bb78a
commit
d6d08db0dd
|
@ -35,7 +35,7 @@ class BaseThrottle(object):
|
||||||
client_addr = addrs[-min(num_proxies, len(xff))]
|
client_addr = addrs[-min(num_proxies, len(xff))]
|
||||||
return client_addr.strip()
|
return client_addr.strip()
|
||||||
|
|
||||||
return xff if xff else remote_addr
|
return ''.join(xff.split()) if xff else remote_addr
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
"""
|
"""
|
||||||
|
@ -173,12 +173,6 @@ class AnonRateThrottle(SimpleRateThrottle):
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
return None # Only throttle unauthenticated requests.
|
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 % {
|
return self.cache_format % {
|
||||||
'scope': self.scope,
|
'scope': self.scope,
|
||||||
'ident': self.get_ident(request)
|
'ident': self.get_ident(request)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user