Skip to content

Commit 3a62e36

Browse files
committed
get_ip_from_request use new Headers class
1 parent 6f30d95 commit 3a62e36

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

aikido_zen/helpers/get_ip_from_request.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
import os
77
from typing import Dict, List, Optional
88

9+
from aikido_zen.helpers.headers import Headers
910
from aikido_zen.helpers.logging import logger
1011

1112

12-
def get_ip_from_request(remote_address, headers: Dict[str, List[str]]) -> Optional[str]:
13+
def get_ip_from_request(remote_address: str, headers: Headers) -> Optional[str]:
1314
"""
1415
Tries and get the IP address from the request, checking for x-forwarded-for
1516
"""
16-
if headers and "X_FORWARDED_FOR" in headers and headers["X_FORWARDED_FOR"]:
17-
if trust_proxy():
18-
x_forwarded_for = get_client_ip_from_x_forwarded_for(
19-
headers["X_FORWARDED_FOR"][-1]
20-
)
21-
22-
if x_forwarded_for and is_ip(x_forwarded_for):
23-
return x_forwarded_for
17+
if headers.get_header("X_FORWARDED_FOR") and trust_proxy():
18+
x_forwarded_for = get_client_ip_from_x_forwarded_for(
19+
headers.get_header("X_FORWARDED_FOR")
20+
)
21+
22+
if x_forwarded_for and is_ip(x_forwarded_for):
23+
return x_forwarded_for
2424

2525
if remote_address and is_ip(remote_address):
2626
return remote_address

0 commit comments

Comments
 (0)