From d6d08db0dd16f4a4a93b69ecf1c5948f375335b0 Mon Sep 17 00:00:00 2001 From: José Padilla Date: Sun, 11 Jan 2015 10:55:56 -0400 Subject: 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. --- rest_framework/throttling.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'rest_framework/throttling.py') diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 361dbddf..7dfe2f96 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -35,7 +35,7 @@ class BaseThrottle(object): client_addr = addrs[-min(num_proxies, len(xff))] return client_addr.strip() - return xff if xff else remote_addr + return ''.join(xff.split()) if xff else remote_addr def wait(self): """ @@ -173,12 +173,6 @@ class AnonRateThrottle(SimpleRateThrottle): 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) -- cgit v1.2.3 From cc13ee0577fb3de9602da634ab9c835749da49c4 Mon Sep 17 00:00:00 2001 From: José Padilla Date: Mon, 12 Jan 2015 08:12:24 -0400 Subject: Fix error when NUM_PROXIES is greater than one --- rest_framework/throttling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/throttling.py') diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 7dfe2f96..0f10136d 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -32,7 +32,7 @@ class BaseThrottle(object): 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 ''.join(xff.split()) if xff else remote_addr -- cgit v1.2.3