def __init__(
self,
uri_or_host,
port=None,
path=None,
proxy_host=None,
proxy_port=None
):
"""THttpClient supports two different types constructor parameters.
THttpClient(host, port, path) - deprecated
THttpClient(uri)
Only the second supports https."""
"""THttpClient supports proxy
THttpClient(host, port, path, proxy_host, proxy_port) - deprecated
ThttpClient(uri, None, None, proxy_host, proxy_port)"""
if port is not None:
warnings.warn(
"Please use the THttpClient('http://host:port/path') syntax",
DeprecationWarning,
stacklevel=2)
self.host = uri_or_host
self.port = port
assert path
self.path = path
self.scheme = 'http'
else:
parsed = urlparse.urlparse(uri_or_host)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or httplib.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or httplib.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
if proxy_host is not None and proxy_port is not None:
self.endpoint_host = proxy_host
self.endpoint_port = proxy_port
self.path = urlparse.urlunparse((
self.scheme,
"%s:%i" % (self.host, self.port),
self.path,
None,
None,
None
))
else:
self.endpoint_host = self.host
self.endpoint_port = self.port
self.__wbuf = StringIO()
self.__http = None
self.__timeout = None
self.__headers = {}
评论列表
文章目录