Add utility to get IP address

This commit is contained in:
Raphael Michel
2019-07-09 16:13:12 +02:00
parent 59daeba477
commit 5a03033255
3 changed files with 17 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
from django.conf import settings
from django.http import StreamingHttpResponse
@@ -9,3 +10,12 @@ class ChunkBasedFileResponse(StreamingHttpResponse):
streaming_content = streaming_content.chunks(self.block_size)
super().__init__(streaming_content, *args, **kwargs)
self['Content-Length'] = filelike.size
def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR')
if settings.TRUST_X_FORWARDED_FOR:
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
return ip