tubesync/app/common/utils.py

17 lines
405 B
Python
Raw Normal View History

2020-11-23 06:32:02 +00:00
from urllib.parse import urlunsplit, urlencode
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
def append_uri_params(uri, params):
uri = str(uri)
qs = urlencode(params)
return urlunsplit(('', '', uri, qs, ''))