def __init__(self, url, *args, **kwargs): super(Transport, self).__init__(url, *args, **kwargs) url_parts = compat.urlparse.urlparse(url) ca_certs = certifi.where() if certifi else None pool_kwargs = { "cert_reqs": "CERT_REQUIRED", "ca_certs": ca_certs, "block": True } if self._server_cert and url_parts.scheme != "http": pool_kwargs.update({ "assert_fingerprint": self.cert_fingerprint, "assert_hostname": False, "cert_reqs": ssl.CERT_NONE }) del pool_kwargs["ca_certs"] elif not self._verify_server_cert and url_parts.scheme != "http": pool_kwargs["cert_reqs"] = ssl.CERT_NONE pool_kwargs["assert_hostname"] = False proxies = compat.getproxies_environment() proxy_url = proxies.get("https", proxies.get("http", None)) if proxy_url and not compat.proxy_bypass_environment(url_parts.netloc): self.http = urllib3.ProxyManager(proxy_url, **pool_kwargs) else: self.http = urllib3.PoolManager(**pool_kwargs)
def __init__(self, url, *args, **kwargs): super(Transport, self).__init__(url, *args, **kwargs) url_parts = compat.urlparse.urlparse(url) # FIXME: Hard coding path to CA bundle right now to work for Amazon Linux - make this configurable pool_kwargs = { "cert_reqs": "CERT_REQUIRED", "ca_certs": "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", "block": True } if self._server_cert and url_parts.scheme != "http": pool_kwargs.update({ "assert_fingerprint": self.cert_fingerprint, "assert_hostname": False, "cert_reqs": ssl.CERT_NONE }) del pool_kwargs["ca_certs"] elif not self._verify_server_cert and url_parts.scheme != "http": pool_kwargs["cert_reqs"] = ssl.CERT_NONE pool_kwargs["assert_hostname"] = False proxies = compat.getproxies_environment() proxy_url = proxies.get("https", proxies.get("http", None)) if proxy_url and not compat.proxy_bypass_environment(url_parts.netloc): self.http = urllib3.ProxyManager(proxy_url, **pool_kwargs) else: self.http = urllib3.PoolManager(**pool_kwargs)
def http(self) -> urllib3.PoolManager: if not self._http: url_parts = compat.urlparse.urlparse(self._url) proxies = compat.getproxies_environment() proxy_url = proxies.get("https", proxies.get("http", None)) if proxy_url and not compat.proxy_bypass_environment(url_parts.netloc): self._http = urllib3.ProxyManager(proxy_url, **self._pool_kwargs) else: self._http = urllib3.PoolManager(**self._pool_kwargs) return self._http