From 01267ea0f5d88e1407d9d93d1793dba622cc9694 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 21 Apr 2024 22:55:08 -0700 Subject: [PATCH] Update GetRemoteAddr documentation to clarify that it may return `nil`. (#1149) --- tool/net/help.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tool/net/help.txt b/tool/net/help.txt index ab6af435d..9ff1450a4 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -1160,12 +1160,17 @@ FUNCTIONS >: shared_key1 == shared_key2 true - GetRemoteAddr() → ip:uint32,port:uint16 + GetRemoteAddr() + ├─→ ip:uint32,port:uint16 + └─→ nil Returns client ip4 address and port, e.g. 0x01020304,31337 would represent 1.2.3.4:31337. This is the same as GetClientAddr except - it will use the ip:port from the X-Forwarded-For header, only if - IsPrivateIp or IsLoopbackIp return true. When multiple addresses - are present in the header, the last/right-most address is used. + it will use the ip:port from the X-Forwarded-For header when the + IP returned by GetClientAddr is a trusted IP (returns true when + checked against IsTrustedIp). When multiple addresses are present + in the header, the last/right-most address is used. + Returns `nil` if the address doesn't parse as IPv4 value (e.g. + because it is misformatted or an IPv6 address). GetResponseBody() ├─→ body:str