MCPcopy
hub / github.com/benoitc/gunicorn / _effective_peername

Method _effective_peername

gunicorn/asgi/protocol.py:1304–1329  ·  view source on GitHub ↗

Return the client address advertised via PROXY protocol if any. Falls back to the transport peername when PROXY protocol is disabled, the framing was absent, the parser is the C variant (which currently does not surface PROXY metadata), or the transport peer is not in

(self, peername)

Source from the content-addressed store, hash-verified

1302 self._response_buffer = b"".join(parts)
1303
1304 def _effective_peername(self, peername):
1305 """Return the client address advertised via PROXY protocol if any.
1306
1307 Falls back to the transport peername when PROXY protocol is disabled,
1308 the framing was absent, the parser is the C variant (which currently
1309 does not surface PROXY metadata), or the transport peer is not in
1310 ``proxy_allow_ips`` (defense-in-depth: ``_setup_callback_parser``
1311 already disables PROXY parsing for untrusted peers).
1312 """
1313 if getattr(self.cfg, 'proxy_protocol', 'off') == 'off':
1314 return peername
1315 if not _check_trusted_proxy(
1316 peername,
1317 self.cfg.proxy_allow_ips,
1318 self.cfg.proxy_allow_networks(),
1319 ):
1320 return peername
1321 parser = self._callback_parser
1322 info = getattr(parser, 'proxy_protocol_info', None) if parser else None
1323 if not info:
1324 return peername
1325 client_addr = info.get('client_addr')
1326 client_port = info.get('client_port')
1327 if client_addr is None or client_port is None:
1328 return peername
1329 return (client_addr, client_port)
1330
1331 @staticmethod
1332 def _response_omits_body(method, status):

Calls 3

_check_trusted_proxyFunction · 0.85
proxy_allow_networksMethod · 0.80
getMethod · 0.45