Skip to content

Commit

Permalink
Fix upload part for py3
Browse files Browse the repository at this point in the history
We were urlencoding the Content-Range header because strings are always
text_types. We should not be encoding spaces.
  • Loading branch information
kyleknap committed Apr 7, 2016
1 parent 1a6c464 commit 82becda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion boto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def authorize(self, connection, **kwargs):
for key in self.headers:
val = self.headers[key]
if isinstance(val, six.text_type):
safe = '!"#$%&\'()*+,/:;<=>?@[\\]^`{|}~'
safe = '!"#$%&\'()*+,/:;<=>?@[\\]^`{|}~ '
self.headers[key] = quote(val.encode('utf-8'), safe)
setattr(self, '_headers_quoted', True)

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/glacier/test_layer1.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def test_get_archive_output(self):


class TestGlacierUploadPart(GlacierLayer1ConnectionBase):
def test_upload_part_content_range_header(self):
fake_data = b'\xe2'
self.set_http_response(status_code=204)
self.service_connection.upload_part(
u'unicode_vault_name', 'upload_id', 'linear_hash', 'tree_hash',
(1,2), fake_data)
self.assertEqual(
self.actual_request.headers['Content-Range'], 'bytes 1-2/*')

def test_upload_part_with_unicode_name(self):
fake_data = b'\xe2'
self.set_http_response(status_code=204)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_get_status_error(self):

class TestHTTPRequest(unittest.TestCase):
def test_user_agent_not_url_encoded(self):
headers = {'Some-Header': u'should be url encoded',
headers = {'Some-Header': u'should be encoded \u2713',
'User-Agent': UserAgent}
request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None,
None, {}, headers, 'Body')
Expand All @@ -539,7 +539,7 @@ def mock_add_auth(req, **kwargs):
# Ensure the headers at authorization are as expected i.e.
# the user agent header was not url encoded but the other header was.
self.assertEqual(mock_connection.headers_at_auth,
{'Some-Header': 'should%20be%20url%20encoded',
{'Some-Header': 'should be encoded %E2%9C%93',
'User-Agent': UserAgent})

def test_content_length_str(self):
Expand Down

0 comments on commit 82becda

Please sign in to comment.