forked from TrueCloudLab/s3-tests
refactor header update logic
This commit is contained in:
parent
82a645c625
commit
1dedf26b95
1 changed files with 21 additions and 42 deletions
|
@ -41,57 +41,36 @@ boto_type = None
|
||||||
# HeaderS3Connection and _our_authorize are necessary to be able to arbitrarily
|
# HeaderS3Connection and _our_authorize are necessary to be able to arbitrarily
|
||||||
# overwrite headers. Depending on the version of boto, one or the other is
|
# overwrite headers. Depending on the version of boto, one or the other is
|
||||||
# necessary. We later determine in setup what needs to be used.
|
# necessary. We later determine in setup what needs to be used.
|
||||||
|
|
||||||
|
def _update_headers(headers):
|
||||||
|
global _custom_headers, _remove_headers
|
||||||
|
|
||||||
|
headers.update(_custom_headers)
|
||||||
|
|
||||||
|
for header in _remove_headers:
|
||||||
|
try:
|
||||||
|
del headers[header]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Note: We need to update the headers twice. The first time so the
|
||||||
|
# authentication signing is done correctly. The second time to overwrite any
|
||||||
|
# headers modified or created in the authentication step.
|
||||||
|
|
||||||
class HeaderS3Connection(S3Connection):
|
class HeaderS3Connection(S3Connection):
|
||||||
def fill_in_auth(self, http_request, **kwargs):
|
def fill_in_auth(self, http_request, **kwargs):
|
||||||
global _custom_headers, _remove_headers
|
_update_headers(http_request.headers)
|
||||||
|
|
||||||
# do our header magic
|
|
||||||
final_headers = http_request.headers
|
|
||||||
final_headers.update(_custom_headers)
|
|
||||||
|
|
||||||
for header in _remove_headers:
|
|
||||||
try:
|
|
||||||
del final_headers[header]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
S3Connection.fill_in_auth(self, http_request, **kwargs)
|
S3Connection.fill_in_auth(self, http_request, **kwargs)
|
||||||
|
_update_headers(http_request.headers)
|
||||||
final_headers = http_request.headers
|
|
||||||
final_headers.update(_custom_headers)
|
|
||||||
|
|
||||||
for header in _remove_headers:
|
|
||||||
try:
|
|
||||||
del final_headers[header]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return http_request
|
return http_request
|
||||||
|
|
||||||
|
|
||||||
def _our_authorize(self, connection, **kwargs):
|
def _our_authorize(self, connection, **kwargs):
|
||||||
global _custom_headers, _remove_headers
|
_update_headers(self.headers)
|
||||||
|
|
||||||
# do our header magic
|
|
||||||
final_headers = self.headers
|
|
||||||
final_headers.update(_custom_headers)
|
|
||||||
|
|
||||||
for header in _remove_headers:
|
|
||||||
try:
|
|
||||||
del final_headers[header]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
_orig_authorize(self, connection, **kwargs)
|
_orig_authorize(self, connection, **kwargs)
|
||||||
|
_update_headers(self.headers)
|
||||||
final_headers = self.headers
|
|
||||||
final_headers.update(_custom_headers)
|
|
||||||
|
|
||||||
for header in _remove_headers:
|
|
||||||
try:
|
|
||||||
del final_headers[header]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
|
|
Loading…
Add table
Reference in a new issue