def get_client_ip(request):
    """
    Returns the proper client ip, looking for
    "X-Forwarded-For"
    "X-Forwarded-Host"
    "X-Client-IP"
    "X-Real-IP"
    headers first.
    """
    headers = dict(
        (h.lower(), h_value) for h, h_value in request.headers.items()
    )
    if 'x-forwarded-for' in headers:
        return headers['x-forwarded-for']
    if 'x-forwarded-host' in headers:
        return headers['x-forwarded-host']
    if 'x-client-ip' in headers:
        return headers['x-client-ip']
    if 'x-real-ip' in headers:
        return headers['x-real-ip']
    return request.remote_addr