Commit 4e460726 authored by Aatish Neupane's avatar Aatish Neupane

use x-real-ip headers

parent 8594e604
......@@ -24,12 +24,16 @@ def block_ipv4(get_response):
return get_response(request)
path = request.path_info.lstrip('/')
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
client_ip = x_forwarded_for
else:
client_ip = request.META.get('REMOTE_ADDR')
print(is_ipv6_exempt(path), is_valid_ipv6(client_ip))
real_ip_headers = ['HTTP_X_REAL_IP', 'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR']
client_ip = None
for header in real_ip_headers:
client_ip = request.META.get(header)
if client_ip:
break
if is_valid_ipv6(client_ip) or is_ipv6_exempt(path):
return get_response(request)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment