From 7c27561039826d434fe7e6a1e7a0b7d04333ad36 Mon Sep 17 00:00:00 2001 From: kahnjw Date: Tue, 12 Nov 2013 09:36:33 -0800 Subject: [PATCH] Only use HTTP_X_FORWARDED_FOR if NUM_PROXIES > 0 else use REMOTE_ADDR --- rest_framework/throttling.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 982ca73d9..efbef4e72 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -23,9 +23,10 @@ class BaseThrottle(object): Identify the machine making the request using HTTP_X_FORWARDED_FOR if present, if not use REMOTE_ADDR. """ - if 'HTTP_X_FORWARDED_FOR' in request.META: + num_proxies = api_settings.NUM_PROXIES + + if 'HTTP_X_FORWARDED_FOR' in request.META and num_proxies > 0: xff = request.META.get('HTTP_X_FORWARDED_FOR') - num_proxies = api_settings.NUM_PROXIES return xff.split(',')[-min(num_proxies, len(xff))].strip()