MCPcopy
hub / github.com/urllib3/urllib3 / is_same_host

Method is_same_host

src/urllib3/connectionpool.py:570–590  ·  view source on GitHub ↗

Check if the given ``url`` is a member of the same host as this connection pool.

(self, url: str)

Source from the content-addressed store, hash-verified

568 _close_pool_connections(old_pool)
569
570 def is_same_host(self, url: str) -> bool:
571 """
572 Check if the given ``url`` is a member of the same host as this
573 connection pool.
574 """
575 if url.startswith("/"):
576 return True
577
578 # TODO: Add optional support for socket.gethostbyname checking.
579 scheme, _, host, port, *_ = parse_url(url)
580 scheme = scheme or "http"
581 if host is not None:
582 host = _normalize_host(host, scheme=scheme)
583
584 # Use explicit default port for comparison when none is given
585 if self.port and not port:
586 port = port_by_scheme.get(scheme)
587 elif not self.port and port == port_by_scheme.get(scheme):
588 port = None
589
590 return (scheme, host, port) == (self.scheme, self.host, self.port)
591
592 def urlopen( # type: ignore[override]
593 self,

Calls 3

parse_urlFunction · 0.85
getMethod · 0.80
_normalize_hostFunction · 0.70