def __init__(self, host, port=None, headers={}, block_size=BLOCK_SIZE, connection_timeout=ConnectionPool.DEFAULT_CONNECTION_TIMEOUT, network_timeout=ConnectionPool.DEFAULT_NETWORK_TIMEOUT, disable_ipv6=False, concurrency=1, ssl_options=None, ssl=False, proxy_host=None, proxy_port=None, version=HTTP_11): self.host = host self.port = port connection_host = self.host connection_port = self.port if proxy_host is not None: assert proxy_port is not None, \ 'you have to provide proxy_port if you set proxy_host' self.use_proxy = True connection_host = proxy_host connection_port = proxy_port else: self.use_proxy = False if ssl and ssl_options is None: ssl_options = {} if ssl_options is not None: self.ssl = True self.port = connection_port = self.port or 443 self._connection_pool = SSLConnectionPool( connection_host, connection_port, size=concurrency, ssl_options=ssl_options, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6) else: self.ssl = False self.port = connection_port = self.port or 80 self._connection_pool = ConnectionPool( connection_host, connection_port, size=concurrency, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6) self.version = version self.default_headers = self.DEFAULT_HEADERS.copy() for field, value in headers.iteritems(): self.default_headers[Header(field)] = value self.block_size = block_size self._base_url_string = str(self.get_base_url())
def __init__(self, host, port=None, headers={}, block_size=BLOCK_SIZE, connection_timeout=ConnectionPool.DEFAULT_CONNECTION_TIMEOUT, network_timeout=ConnectionPool.DEFAULT_NETWORK_TIMEOUT, disable_ipv6=False, concurrency=1, ssl_options=None, ssl=False, insecure=False, proxy_host=None, proxy_port=None, version=HTTP_11, headers_type=Headers): self.host = host self.port = port connection_host = self.host connection_port = self.port if proxy_host is not None: assert proxy_port is not None, \ 'you have to provide proxy_port if you set proxy_host' self.use_proxy = True connection_host = proxy_host connection_port = proxy_port else: self.use_proxy = False if ssl and ssl_options is None: ssl_options = {} if ssl_options is not None: self.ssl = True if not self.port: self.port = 443 if not connection_port: connection_port = self.port self._connection_pool = SSLConnectionPool( connection_host, connection_port, size=concurrency, ssl_options=ssl_options, insecure=insecure, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6) else: self.ssl = False if not self.port: self.port = 80 if not connection_port: connection_port = self.port self._connection_pool = ConnectionPool( connection_host, connection_port, size=concurrency, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6) self.version = version self.headers_type = headers_type self.default_headers = headers_type() self.default_headers.update(self.DEFAULT_HEADERS) self.default_headers.update(headers) self.block_size = block_size self._base_url_string = str(self.get_base_url())
def __init__(self, host, port=None, headers=None, block_size=BLOCK_SIZE, connection_timeout=ConnectionPool.DEFAULT_CONNECTION_TIMEOUT, network_timeout=ConnectionPool.DEFAULT_NETWORK_TIMEOUT, disable_ipv6=False, concurrency=1, ssl=False, ssl_options=None, ssl_context_factory=None, insecure=False, proxy_host=None, proxy_port=None, version=HTTP_11, headers_type=Headers): if headers is None: headers = {} self.host = host self.port = port connection_host = self.host connection_port = self.port if proxy_host is not None: assert proxy_port is not None, \ 'you have to provide proxy_port if you set proxy_host' self.use_proxy = True connection_host = proxy_host connection_port = proxy_port else: self.use_proxy = False if ssl: ssl_options = ssl_options.copy() if ssl_options else {} if ssl_options is not None: if ssl_context_factory is not None: requested_hostname = headers.get('host', self.host) ssl_options.setdefault('server_hostname', requested_hostname) self.ssl = True if not self.port: self.port = 443 if not connection_port: connection_port = self.port # Import SSL as late as possible, fail hard with Import Error from geventhttpclient.connectionpool import SSLConnectionPool self._connection_pool = SSLConnectionPool( connection_host, connection_port, self.host, self.port, size=concurrency, ssl_options=ssl_options, ssl_context_factory=ssl_context_factory, insecure=insecure, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6, use_proxy=self.use_proxy) else: self.ssl = False if not self.port: self.port = 80 if not connection_port: connection_port = self.port self._connection_pool = ConnectionPool( connection_host, connection_port, self.host, self.port, size=concurrency, network_timeout=network_timeout, connection_timeout=connection_timeout, disable_ipv6=disable_ipv6, use_proxy=self.use_proxy) self.version = version self.headers_type = headers_type self.default_headers = headers_type() self.default_headers.update(self.DEFAULT_HEADERS) self.default_headers.update(headers) self.block_size = block_size self._base_url_string = str(self.get_base_url())