def __init__(self, host, port=None, secure=None, ssl_context=None, proxy_host=None, proxy_port=None, proxy_headers=None, timeout=None, **kwargs): if port is None: self.host, self.port = to_host_port_tuple(host, default_port=80) else: self.host, self.port = host, port # Record whether we plan to secure the request. In future this should # be extended to a security profile, but a bool will do for now. # TODO: Actually do something with this! if secure is not None: self.secure = secure elif self.port == 443: self.secure = True else: self.secure = False # only send http upgrade headers for non-secure connection self._send_http_upgrade = not self.secure self._enable_push = kwargs.get('enable_push') self.ssl_context = ssl_context self._sock = None # Keep the current request method in order to be able to know # in get_response() what was the request verb. self._current_request_method = None # Setup proxy details if applicable. if proxy_host and proxy_port is None: self.proxy_host, self.proxy_port = to_host_port_tuple( proxy_host, default_port=8080) elif proxy_host: self.proxy_host, self.proxy_port = proxy_host, proxy_port else: self.proxy_host = None self.proxy_port = None self.proxy_headers = proxy_headers #: The size of the in-memory buffer used to store data from the #: network. This is used as a performance optimisation. Increase buffer #: size to improve performance: decrease it to conserve memory. #: Defaults to 64kB. self.network_buffer_size = 65536 #: The object used to perform HTTP/1.1 parsing. Needs to conform to #: the standard hyper parsing interface. self.parser = Parser() # timeout self._timeout = timeout
def __init__(self, host, port=None, secure=None, ssl_context=None, proxy_host=None, proxy_port=None, **kwargs): if port is None: try: self.host, self.port = host.split(':') self.port = int(self.port) except ValueError: self.host, self.port = host, 80 else: self.host, self.port = host, port # Record whether we plan to secure the request. In future this should # be extended to a security profile, but a bool will do for now. # TODO: Actually do something with this! if secure is not None: self.secure = secure elif self.port == 443: self.secure = True else: self.secure = False # only send http upgrade headers for non-secure connection self._send_http_upgrade = not self.secure self.ssl_context = ssl_context self._sock = None # Setup proxy details if applicable. if proxy_host: if proxy_port is None: try: self.proxy_host, self.proxy_port = proxy_host.split(':') except ValueError: self.proxy_host, self.proxy_port = proxy_host, 8080 else: self.proxy_port = int(self.proxy_port) else: self.proxy_host, self.proxy_port = proxy_host, proxy_port else: self.proxy_host = None self.proxy_port = None #: The size of the in-memory buffer used to store data from the #: network. This is used as a performance optimisation. Increase buffer #: size to improve performance: decrease it to conserve memory. #: Defaults to 64kB. self.network_buffer_size = 65536 #: The object used to perform HTTP/1.1 parsing. Needs to conform to #: the standard hyper parsing interface. self.parser = Parser()