Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always convert header values to str() #852

Merged
merged 1 commit into from Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion botocore/serialize.py
Expand Up @@ -483,7 +483,7 @@ def _partition_parameters(self, partitioned, param_name,
elif location == 'header':
shape = shape_members[param_name]
value = self._convert_header_value(shape, param_value)
partitioned['headers'][key_name] = value
partitioned['headers'][key_name] = str(value)
elif location == 'headers':
# 'headers' is a bit of an oddball. The ``key_name``
# is actually really a prefix for the header names:
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/test_s3.py
Expand Up @@ -206,3 +206,21 @@ def test_provided_endpoint_url_for_path_addressing(self):
request_sent = mock_send.call_args[0][0]
self.assertEqual(
'https://foo.amazonaws.com/mybucket/mykey', request_sent.url)


class TestCanSendIntegerHeaders(BaseSessionTest):

def test_int_values_with_sigv4(self):
s3 = self.session.create_client(
's3', config=Config(signature_version='s3v4'))
with mock.patch('botocore.endpoint.Session.send') as mock_send:
mock_send.return_value = mock.Mock(status_code=200,
content=b'',
headers={})
s3.upload_part(Bucket='foo', Key='bar', Body=b'foo',
UploadId='bar', PartNumber=1, ContentLength=3)
headers = mock_send.call_args[0][0].headers
# Verify that the request integer value of 3 has been converted to
# string '3'. This also means we've made it pass the signer which
# expects string values in order to sign properly.
self.assertEqual(headers['Content-Length'], '3')
38 changes: 38 additions & 0 deletions tests/unit/test_serialize.py
Expand Up @@ -402,3 +402,41 @@ def test_instantiate_with_validation(self):

with self.assertRaises(ParamValidationError):
self.assert_serialize_invalid_parameter(request_serializer)


class TestHeaderSerialization(BaseModelWithBlob):
def setUp(self):
self.model = {
'metadata': {'protocol': 'rest-xml', 'apiVersion': '2014-01-01'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'ContentLength': {
'shape': 'Integer',
'location': 'header',
'locationName': 'Content-Length'
},
}
},
'Integer': {
'type': 'integer'
},
}
}
self.service_model = ServiceModel(self.model)

def test_always_serialized_as_str(self):
request = self.serialize_to_request({'ContentLength': 100})
self.assertEqual(request['headers']['Content-Length'], '100')