mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Only use HTTP_X_FORWARDED_FOR if NUM_PROXIES > 0 else use REMOTE_ADDR
This commit is contained in:
parent
23af9a1a22
commit
7c27561039
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user