Skip to content

Commit 98b0262

Browse files
committed
Merge pull request tornadoweb#700 from icaromedeiros/master
Digest authentication for curl_httpclient
2 parents e0e8f7e + e8bc6af commit 98b0262

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tornado/curl_httpclient.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ def ioctl(cmd):
411411

412412
if request.auth_username is not None:
413413
userpwd = "%s:%s" % (request.auth_username, request.auth_password or '')
414-
curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
414+
415+
if request.auth_mode is None or request.auth_mode == "basic":
416+
curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
417+
elif request.auth_mode == "digest":
418+
curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST)
419+
415420
curl.setopt(pycurl.USERPWD, native_str(userpwd))
416421
gen_log.debug("%s %s (username: %r)", request.method, request.url,
417422
request.auth_username)

tornado/httpclient.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class HTTPRequest(object):
242242
validate_cert=True)
243243

244244
def __init__(self, url, method="GET", headers=None, body=None,
245-
auth_username=None, auth_password=None,
245+
auth_username=None, auth_password=None, auth_mode=None,
246246
connect_timeout=None, request_timeout=None,
247247
if_modified_since=None, follow_redirects=None,
248248
max_redirects=None, user_agent=None, use_gzip=None,
@@ -259,8 +259,9 @@ def __init__(self, url, method="GET", headers=None, body=None,
259259
:arg string method: HTTP method, e.g. "GET" or "POST"
260260
:arg headers: Additional HTTP headers to pass on the request
261261
:type headers: `~tornado.httputil.HTTPHeaders` or `dict`
262-
:arg string auth_username: Username for HTTP "Basic" authentication
263-
:arg string auth_password: Password for HTTP "Basic" authentication
262+
:arg string auth_username: Username for HTTP authentication
263+
:arg string auth_password: Password for HTTP authentication
264+
:arg string auth_mode: Authentication mode (basic, digest)
264265
:arg float connect_timeout: Timeout for initial connection in seconds
265266
:arg float request_timeout: Timeout for entire request in seconds
266267
:arg if_modified_since: Timestamp for ``If-Modified-Since`` header
@@ -322,6 +323,7 @@ def __init__(self, url, method="GET", headers=None, body=None,
322323
self.body = utf8(body)
323324
self.auth_username = auth_username
324325
self.auth_password = auth_password
326+
self.auth_mode = auth_mode
325327
self.connect_timeout = connect_timeout
326328
self.request_timeout = request_timeout
327329
self.follow_redirects = follow_redirects

0 commit comments

Comments
 (0)