2023-08-30 20:55:31 +02:00
|
|
|
import os
|
|
|
|
import time
|
2023-10-16 23:34:54 +02:00
|
|
|
|
2023-08-30 20:55:31 +02:00
|
|
|
from dotenv import load_dotenv
|
2023-09-23 21:41:48 +02:00
|
|
|
from slowapi.util import get_remote_address
|
2023-08-30 20:55:31 +02:00
|
|
|
|
|
|
|
load_dotenv()
|
2023-08-04 17:29:49 +02:00
|
|
|
|
2023-10-16 23:34:54 +02:00
|
|
|
def get_ip(request) -> str:
|
2023-08-12 17:49:31 +02:00
|
|
|
"""Get the IP address of the incoming request."""
|
|
|
|
|
2023-10-16 23:34:54 +02:00
|
|
|
detected_ip = request.headers.get('cf-connecting-ip', get_remote_address(request))
|
2023-08-05 02:30:42 +02:00
|
|
|
return detected_ip
|
2023-08-27 04:29:16 +02:00
|
|
|
|
2023-08-30 20:55:31 +02:00
|
|
|
def get_ratelimit_key(request) -> str:
|
2023-08-27 04:29:16 +02:00
|
|
|
"""Get the IP address of the incoming request."""
|
2023-10-16 23:34:54 +02:00
|
|
|
|
|
|
|
ip = get_ip(request)
|
|
|
|
return ip
|