From 3184e62ccba0167ee88d437049b0cb3baf5c13e4 Mon Sep 17 00:00:00 2001 From: zhimin Date: Fri, 2 Sep 2016 17:23:09 +0800 Subject: [PATCH] curl_httpclient: Add proxy_auth_mode to support digest for proxy authentication --- tornado/curl_httpclient.py | 9 +++++++++ tornado/httpclient.py | 17 ++++++++++------- tornado/simple_httpclient.py | 3 ++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index f0e43c0f2..bef78419f 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -345,6 +345,15 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): credentials = '%s:%s' % (request.proxy_username, request.proxy_password) curl.setopt(pycurl.PROXYUSERPWD, credentials) + + if (request.proxy_auth_mode is None or + request.proxy_auth_mode == "basic"): + curl.setopt(pycurl.PROXYAUTH, pycurl.HTTPAUTH_BASIC) + elif request.proxy_auth_mode == "digest": + curl.setopt(pycurl.PROXYAUTH, pycurl.HTTPAUTH_DIGEST) + else: + raise ValueError( + "Unsupported proxy_auth_mode %s" % request.proxy_auth_mode) else: curl.setopt(pycurl.PROXY, '') curl.unsetopt(pycurl.PROXYUSERPWD) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 762919ee8..635e265c3 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -310,10 +310,10 @@ class HTTPRequest(object): network_interface=None, streaming_callback=None, header_callback=None, prepare_curl_callback=None, proxy_host=None, proxy_port=None, proxy_username=None, - proxy_password=None, allow_nonstandard_methods=None, - validate_cert=None, ca_certs=None, - allow_ipv6=None, - client_key=None, client_cert=None, body_producer=None, + proxy_password=None, proxy_auth_mode=None, + allow_nonstandard_methods=None, validate_cert=None, + ca_certs=None, allow_ipv6=None, client_key=None, + client_cert=None, body_producer=None, expect_100_continue=False, decompress_response=None, ssl_options=None): r"""All parameters except ``url`` are optional. @@ -372,12 +372,14 @@ class HTTPRequest(object): a ``pycurl.Curl`` object to allow the application to make additional ``setopt`` calls. :arg string proxy_host: HTTP proxy hostname. To use proxies, - ``proxy_host`` and ``proxy_port`` must be set; ``proxy_username`` and - ``proxy_pass`` are optional. Proxies are currently only supported - with ``curl_httpclient``. + ``proxy_host`` and ``proxy_port`` must be set; ``proxy_username``, + ``proxy_pass`` and ``proxy_auth_mode`` are optional. Proxies are + currently only supported with ``curl_httpclient``. :arg int proxy_port: HTTP proxy port :arg string proxy_username: HTTP proxy username :arg string proxy_password: HTTP proxy password + :arg string proxy_auth_mode: HTTP proxy Authentication mode; + default is "basic". supports "basic" and "digest" :arg bool allow_nonstandard_methods: Allow unknown values for ``method`` argument? :arg bool validate_cert: For HTTPS requests, validate the server's @@ -430,6 +432,7 @@ class HTTPRequest(object): self.proxy_port = proxy_port self.proxy_username = proxy_username self.proxy_password = proxy_password + self.proxy_auth_mode = proxy_auth_mode self.url = url self.method = method self.body = body diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 82f868644..adcf38b25 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -330,7 +330,8 @@ class _HTTPConnection(httputil.HTTPMessageDelegate): raise KeyError("unknown method %s" % self.request.method) for key in ('network_interface', 'proxy_host', 'proxy_port', - 'proxy_username', 'proxy_password'): + 'proxy_username', 'proxy_password', + 'proxy_auth_mode'): if getattr(self.request, key, None): raise NotImplementedError('%s not supported' % key) if "Connection" not in self.request.headers: -- 2.47.2