def create_pool(self, host): """ Create a new HTTP(S)ConnectionPool for a (host, port) tuple """ options = { "timeout": self.timeout, "strict": True, "retries": host.get("retries", 2), # Max of 5 connections open per host # this is arbitrary. The # of connections can burst # above 5 if needed becuase we're also setting # block=False "maxsize": host.get("maxsize", 5), "block": False, "headers": host.get("headers", {}), } if "basic_auth" in host: options["headers"]["authorization"] = encode_basic_auth( host["basic_auth"]) # Support backwards compatibility with `http_port` if "http_port" in host: import warnings warnings.warn("'http_port' has been deprecated. Use 'port'.", DeprecationWarning) host["port"] = host.pop("http_port") addr = host.get("host", "127.0.0.1") port = int(host.get("port", 8098)) secure = host.get("secure", False) if addr[:1] == "/": pool_cls = UnixHTTPConnectionPool elif not secure: pool_cls = HTTPConnectionPool else: pool_cls = HTTPSConnectionPool verify_ssl = host.get("verify_ssl", False) if verify_ssl: options.extend({ "cert_reqs": host.get("cert_reqs", "CERT_REQUIRED"), "ca_certs": host.get("ca_certs", ca_certs()), }) if self.tcp_keepalive: options[ "socket_options"] = pool_cls.ConnectionCls.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) ] return pool_cls(addr, port, **options)
def create_pool(self, host): """ Create a new HTTP(S)ConnectionPool for a (host, port) tuple """ options = { 'timeout': self.timeout, 'strict': True, 'retries': host.get('retries', 2), # Max of 5 connections open per host # this is arbitrary. The # of connections can burst # above 5 if needed becuase we're also setting # block=False 'maxsize': host.get('maxsize', 5), 'block': False, 'headers': host.get('headers', {}) } if 'basic_auth' in host: options['headers']['authorization'] = encode_basic_auth( host['basic_auth']) # Support backwards compatibility with `http_port` if 'http_port' in host: import warnings warnings.warn("'http_port' has been deprecated. Use 'port'.", DeprecationWarning) host['port'] = host.pop('http_port') addr = host.get('host', '127.0.0.1') port = int(host.get('port', 8098)) secure = host.get('secure', False) if addr[:1] == '/': pool_cls = UnixHTTPConnectionPool elif not secure: pool_cls = HTTPConnectionPool else: pool_cls = HTTPSConnectionPool verify_ssl = host.get('verify_ssl', False) if verify_ssl: options.extend({ 'cert_reqs': host.get('cert_reqs', 'CERT_REQUIRED'), 'ca_certs': host.get('ca_certs', ca_certs()) }) if self.tcp_keepalive: options[ 'socket_options'] = pool_cls.ConnectionCls.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] return pool_cls(addr, port, **options)
def create_pool(self, host): """ Create a new HTTP(S)ConnectionPool for a (host, port) tuple """ options = { 'timeout': self.timeout, 'strict': True, 'retries': host.get('retries', 2), # Max of 5 connections open per host # this is arbitrary. The # of connections can burst # above 5 if needed becuase we're also setting # block=False 'maxsize': host.get('maxsize', 5), 'block': False, 'headers': host.get('headers', {}) } if 'basic_auth' in host: options['headers']['authorization'] = encode_basic_auth(host['basic_auth']) # Support backwards compatibility with `http_port` if 'http_port' in host: import warnings warnings.warn("'http_port' has been deprecated. Use 'port'.", DeprecationWarning) host['port'] = host.pop('http_port') addr = host.get('host', '127.0.0.1') port = int(host.get('port', 8098)) secure = host.get('secure', False) if addr[:1] == '/': pool_cls = UnixHTTPConnectionPool elif not secure: pool_cls = HTTPConnectionPool else: pool_cls = HTTPSConnectionPool verify_ssl = host.get('verify_ssl', False) if verify_ssl: options.extend( { 'cert_reqs': host.get('cert_reqs', 'CERT_REQUIRED'), 'ca_certs': host.get('ca_certs', ca_certs()) } ) if self.tcp_keepalive: options['socket_options'] = pool_cls.ConnectionCls.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] return pool_cls(addr, port, **options)
def create_pool(self, host): """ Create a new HTTP(S)ConnectionPool for a (host, port) tuple """ options = { 'timeout': self.timeout, 'strict': True, # We don't need urllib3's retries, since we'll retry # on a different host ourselves 'retries': False, # Max of 5 connections open per host # this is arbitrary. The # of connections can burst # above 5 if needed becuase we're also setting # block=False 'maxsize': 5, 'block': False, } if self.tcp_keepalive: options[ 'socket_options'] = HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] # Support backwards compatibility with `http_port` if 'http_port' in host: import warnings warnings.warn("'http_port' has been deprecated. Use 'port'.", DeprecationWarning) host['port'] = host.pop('http_port') addr = host.get('host', '127.0.0.1') port = int(host.get('port', 8098)) secure = host.get('secure', False) if not secure: connection_cls = HTTPConnectionPool else: connection_cls = HTTPSConnectionPool verify_ssl = host.get('verify_ssl', False) if verify_ssl: options.extend({ 'cert_reqs': host.get('cert_reqs', 'CERT_REQUIRED'), 'ca_certs': host.get('ca_certs', ca_certs()) }) return connection_cls(addr, port, **options)
def create_pool(self, host): """ Create a new HTTP(S)ConnectionPool for a (host, port) tuple """ options = { 'timeout': self.timeout, 'strict': True, # We don't need urllib3's retries, since we'll retry # on a different host ourselves 'retries': False, # Max of 5 connections open per host # this is arbitrary. The # of connections can burst # above 5 if needed becuase we're also setting # block=False 'maxsize': 5, 'block': False, } if self.tcp_keepalive: options['socket_options'] = HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] # Support backwards compatibility with `http_port` if 'http_port' in host: import warnings warnings.warn("'http_port' has been deprecated. Use 'port'.", DeprecationWarning) host['port'] = host.pop('http_port') addr = host.get('host', '127.0.0.1') port = int(host.get('port', 8098)) secure = host.get('secure', False) if not secure: connection_cls = HTTPConnectionPool else: connection_cls = HTTPSConnectionPool verify_ssl = host.get('verify_ssl', False) if verify_ssl: options.extend({ 'cert_reqs': host.get('cert_reqs', 'CERT_REQUIRED'), 'ca_certs': host.get('ca_certs', ca_certs()) }) return connection_cls(addr, port, **options)