From 0c60a3ad4138db3e59772fea85438509b118497b Mon Sep 17 00:00:00 2001 From: Luke Morfitt Date: Mon, 1 Aug 2016 11:47:08 +0100 Subject: [PATCH 1/2] Fix for AzureBlobStorage not allowing upload with 400 error (https://issues.apache.org/jira/browse/LIBCLOUD-842). The issue was created when a fix for "AWSRequestSignerAlgorithmV4" (https://github.com/apache/libcloud/commit/4bff0f076776e6d59945381c1e2969826131fc11) was added. This caused the heads "host" and "accept_encoding" to be removed from the requests to AzureBlobStorage. The Fix retains the current functionality and sets the headers on for Azure. --- libcloud/common/azure.py | 2 ++ libcloud/common/base.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libcloud/common/azure.py b/libcloud/common/azure.py index b7f9ffc549..cbba05219f 100644 --- a/libcloud/common/azure.py +++ b/libcloud/common/azure.py @@ -112,6 +112,8 @@ class AzureConnection(ConnectionUserAndKey): responseCls = AzureResponse rawResponseCls = AzureRawResponse + skip_host = False + skip_accept_encoding = False def add_default_params(self, params): return params diff --git a/libcloud/common/base.py b/libcloud/common/base.py index 540244dc8c..ddebf493e0 100644 --- a/libcloud/common/base.py +++ b/libcloud/common/base.py @@ -532,6 +532,8 @@ class Connection(object): retry_delay = None allow_insecure = True + skip_host = True + skip_accept_encoding = True def __init__(self, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, retry_delay=None, backoff=None): @@ -778,6 +780,9 @@ def request(self, action, params=None, data=None, headers=None, else: headers.update({'Host': self.host}) + skip_host = self.skip_host + skip_accept_encoding = self.skip_accept_encoding + if data: data = self.encode_data(data) headers['Content-Length'] = str(len(data)) @@ -808,8 +813,8 @@ def request(self, action, params=None, data=None, headers=None, # instead of dealing with splitting and sending the file ourselves? if raw: self.connection.putrequest(method, url, - skip_host=1, - skip_accept_encoding=1) + skip_host=skip_host, + skip_accept_encoding=skip_accept_encoding) for key, value in list(headers.items()): self.connection.putheader(key, str(value)) From d2f19c991298b618e870e13d92071e1480808f6b Mon Sep 17 00:00:00 2001 From: Luke Morfitt Date: Mon, 1 Aug 2016 12:39:58 +0100 Subject: [PATCH 2/2] Autopep8 clean up errors with flake8 --- libcloud/common/base.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libcloud/common/base.py b/libcloud/common/base.py index ddebf493e0..6a97564b84 100644 --- a/libcloud/common/base.py +++ b/libcloud/common/base.py @@ -118,6 +118,7 @@ class HTTPResponse(httplib.HTTPResponse): # In particular this happens on S3 when calls are made to get_object to # objects that don't exist. # This applies the behaviour from 2.7, fixing the hangs. + def read(self, amt=None): if self.fp is None: return '' @@ -354,6 +355,7 @@ def _log_response(self, r): # this is evil. laugh with me. ha arharhrhahahaha class fakesock(object): + def __init__(self, s): self.s = s @@ -812,9 +814,11 @@ def request(self, action, params=None, data=None, headers=None, # @TODO: Should we just pass File object as body to request method # instead of dealing with splitting and sending the file ourselves? if raw: - self.connection.putrequest(method, url, - skip_host=skip_host, - skip_accept_encoding=skip_accept_encoding) + self.connection.putrequest( + method, + url, + skip_host=skip_host, + skip_accept_encoding=skip_accept_encoding) for key, value in list(headers.items()): self.connection.putheader(key, str(value)) @@ -1055,6 +1059,7 @@ class ConnectionKey(Connection): """ Base connection class which accepts a single ``key`` argument. """ + def __init__(self, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None): """ @@ -1074,6 +1079,7 @@ class CertificateConnection(Connection): """ Base connection class which accepts a single ``cert_file`` argument. """ + def __init__(self, cert_file, secure=True, host=None, port=None, url=None, proxy_url=None, timeout=None, backoff=None, retry_delay=None): """