summaryrefslogtreecommitdiff
path: root/swiftclient/client.py
diff options
context:
space:
mode:
authorStuart McLaren <stuart.mclaren@hp.com>2013-01-18 14:17:21 +0000
committerStuart McLaren <stuart.mclaren@hp.com>2013-06-04 16:33:18 +0000
commit790f087a67fcc0cc7730cedd1a225d58a82ddf5d (patch)
treeaf269fc89acca0a27769b18df4d6f339217adfd4 /swiftclient/client.py
parent2d12f09c66e0221ba7f43cc64677c05486a42ea6 (diff)
downloadpython-swiftclient-790f087a67fcc0cc7730cedd1a225d58a82ddf5d.tar.gz
Add option to disable SSL compression
Allows optionally disabling SSL compression. This can significantly improve HTTPS upload/download performance in some cases -- in particular when the object is not compressible and you have very high network bandwidth. Implements blueprint ssl-compression. Change-Id: I1260055f9c2e83cdabfeb51aed11b3899bed4d55
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r--swiftclient/client.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index afd85f0..cb09a37 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -28,6 +28,10 @@ from urlparse import urlparse, urlunparse
from httplib import HTTPException, HTTPConnection, HTTPSConnection
from time import sleep
+try:
+ from swiftclient.https_connection import HTTPSConnectionNoSSLComp
+except ImportError:
+ HTTPSConnectionNoSSLComp = HTTPSConnection
logger = logging.getLogger("swiftclient")
@@ -141,23 +145,32 @@ class ClientException(Exception):
return b and '%s: %s' % (a, b) or a
-def http_connection(url, proxy=None):
+def http_connection(url, proxy=None, ssl_compression=True):
"""
Make an HTTPConnection or HTTPSConnection
:param url: url to connect to
:param proxy: proxy to connect through, if any; None by default; str of the
format 'http://127.0.0.1:8888' to set one
+ :param ssl_compression: Whether to enable compression at the SSL layer.
+ If set to 'False' and the pyOpenSSL library is
+ present an attempt to disable SSL compression
+ will be made. This may provide a performance
+ increase for https upload/download operations.
:returns: tuple of (parsed url, connection object)
:raises ClientException: Unable to handle protocol scheme
"""
url = encode_utf8(url)
parsed = urlparse(url)
proxy_parsed = urlparse(proxy) if proxy else None
+ host = proxy_parsed if proxy else parsed.netloc
if parsed.scheme == 'http':
- conn = HTTPConnection((proxy_parsed if proxy else parsed).netloc)
+ conn = HTTPConnection(host)
elif parsed.scheme == 'https':
- conn = HTTPSConnection((proxy_parsed if proxy else parsed).netloc)
+ if ssl_compression is True:
+ conn = HTTPSConnection(host)
+ else:
+ conn = HTTPSConnectionNoSSLComp(host)
else:
raise ClientException('Cannot handle protocol scheme %s for url %s' %
(parsed.scheme, repr(url)))
@@ -956,7 +969,8 @@ class Connection(object):
def __init__(self, authurl=None, user=None, key=None, retries=5,
preauthurl=None, preauthtoken=None, snet=False,
starting_backoff=1, tenant_name=None, os_options=None,
- auth_version="1", cacert=None, insecure=False):
+ auth_version="1", cacert=None, insecure=False,
+ ssl_compression=True):
"""
:param authurl: authentication URL
:param user: user name to authenticate as
@@ -975,6 +989,11 @@ class Connection(object):
tenant_name, object_storage_url, region_name
:param insecure: Allow to access insecure keystone server.
The keystone's certificate will not be verified.
+ :param ssl_compression: Whether to enable compression at the SSL layer.
+ If set to 'False' and the pyOpenSSL library is
+ present an attempt to disable SSL compression
+ will be made. This may provide a performance
+ increase for https upload/download operations.
"""
self.authurl = authurl
self.user = user
@@ -992,6 +1011,7 @@ class Connection(object):
self.os_options['tenant_name'] = tenant_name
self.cacert = cacert
self.insecure = insecure
+ self.ssl_compression = ssl_compression
def get_auth(self):
return get_auth(self.authurl,
@@ -1004,7 +1024,8 @@ class Connection(object):
insecure=self.insecure)
def http_connection(self):
- return http_connection(self.url)
+ return http_connection(self.url,
+ ssl_compression=self.ssl_compression)
def _retry(self, reset_func, func, *args, **kwargs):
self.attempts = 0