diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 8abaf1409..02a0cd122 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -63,6 +63,7 @@ DEFAULTS = { 'user': None, 'anon': None, }, + 'NUM_PROXIES': 0, # Pagination 'PAGINATE_BY': None, diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index df0d130df..1c8c6941d 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -21,7 +21,9 @@ class BaseThrottle(object): def get_ident(self, request): if 'HTTP_X_FORWARDED_FOR' in request.META: xff = request.META.get('HTTP_X_FORWARDED_FOR') - return xff.split(',')[0].strip() + num_proxies = api_settings.NUM_PROXIES + + return xff.split(',')[-min(num_proxies, len(xff))].strip() return request.META.get('REMOTE_ADDR', None)