Skip to content

Commit

Permalink
Merge pull request spez#5 from christopherhesse/curl-settings
Browse files Browse the repository at this point in the history
curl settings [chris]
  • Loading branch information
christopherhesse committed Jul 27, 2012
2 parents 2339ec2 + 6a63b4a commit 0345e19
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tornado/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ def __init__(self, url, method="GET", headers=None, body=None,
network_interface=None, streaming_callback=None,
header_callback=None, prepare_curl_callback=None,
proxy_host=None, proxy_port=None, proxy_username=None,
proxy_password='', allow_nonstandard_methods=False):
proxy_password='', allow_nonstandard_methods=False,
curl_settings=None):
if headers is None:
headers = httputil.HTTPHeaders()
if if_modified_since:
Expand Down Expand Up @@ -421,6 +422,7 @@ def __init__(self, url, method="GET", headers=None, body=None,
self.prepare_curl_callback = prepare_curl_callback
self.allow_nonstandard_methods = allow_nonstandard_methods
self.start_time = time.time()
self.curl_settings = curl_settings or set()


class HTTPResponse(object):
Expand Down Expand Up @@ -611,6 +613,25 @@ def ioctl(cmd):
# there may not be any other threads running at the time we call
# threading.activeCount.
curl.setopt(pycurl.NOSIGNAL, 1)

# special curl settings used for different scrapers
if 'no-keep-alive' in request.curl_settings:
curl.setopt(pycurl.FORBID_REUSE, True)
curl.setopt(pycurl.FRESH_CONNECT, True)
else:
curl.setopt(pycurl.FORBID_REUSE, False)
curl.setopt(pycurl.FRESH_CONNECT, False)

if 'tlsv1' in request.curl_settings:
curl.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_TLSv1)
else:
curl.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_DEFAULT)

if '3des' in request.curl_settings:
curl.setopt(pycurl.SSL_CIPHER_LIST, '3DES')
else:
curl.unsetopt(pycurl.SSL_CIPHER_LIST)

if request.prepare_curl_callback is not None:
request.prepare_curl_callback(curl)

Expand Down

0 comments on commit 0345e19

Please sign in to comment.