File tree 1 file changed +5
-3
lines changed
troncos/contrib/asgi/logging
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,18 @@ def __init__(
23
23
) -> None :
24
24
self ._list : list [tuple [bytes , bytes ]] = list (scope ["headers" ])
25
25
26
- def add_client (self , client : tuple [str , int ]) -> None :
26
+ def add_client (self , client : tuple [str , int ] | None ) -> None :
27
27
"""
28
28
The client IP is not stored in the ASGI headers by default.
29
29
Add the client ip to make sure we use it as a fallback if no
30
30
proxy headers are set.
31
31
"""
32
+ host = client [0 ] if client else "<no-host>"
33
+ port = client [1 ] if client else 0
32
34
self ._list .append (
33
35
(
34
36
"REMOTE_ADDR" .encode ("latin-1" ),
35
- f"{ client [ 0 ] } :{ client [ 1 ] } " .encode ("latin-1" ),
37
+ f"{ host } :{ port } " .encode ("latin-1" ),
36
38
)
37
39
)
38
40
@@ -109,7 +111,7 @@ async def __call__(
109
111
ipware = IpWare ()
110
112
111
113
headers = Headers (scope = scope )
112
- headers .add_client (scope [ "client" ] )
114
+ headers .add_client (scope . get ( "client" ) )
113
115
114
116
client_ip , _ = ipware .get_client_ip (cast (dict [str , str ], headers ))
115
117
You can’t perform that action at this time.
0 commit comments