From: julien4215 <120588494+julien4215@users.noreply.github.com> Date: Thu, 25 Apr 2024 06:49:38 +0000 (+0200) Subject: Fix documentation on client address type (#2580) X-Git-Tag: 0.38.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f16bf5c25e126200701f6e04330864f4a91a898;p=thirdparty%2Fstarlette.git Fix documentation on client address type (#2580) --- diff --git a/docs/requests.md b/docs/requests.md index f8d19bb9..9140bb96 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -60,8 +60,7 @@ For example: `request.path_params['username']` #### Client Address -The client's remote address is exposed as a named two-tuple `request.client`. -Either item in the tuple may be `None`. +The client's remote address is exposed as a named two-tuple `request.client` (or `None`). The hostname or IP address: `request.client.host` diff --git a/starlette/requests.py b/starlette/requests.py index b27e8e1e..a2fdfd81 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -145,7 +145,7 @@ class HTTPConnection(typing.Mapping[str, typing.Any]): @property def client(self) -> Address | None: - # client is a 2 item tuple of (host, port), None or missing + # client is a 2 item tuple of (host, port), None if missing host_port = self.scope.get("client") if host_port is not None: return Address(*host_port)