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

Encode string request body as utf-8 #125

Merged
merged 1 commit into from
Aug 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,37 +215,34 @@ def setUp(self):
self._delete_dir(self._object_dir)

def test_object(self):
contents = "vegans are better than everyone"
body = "this unicode character Ě triggers ML-7498"
body_bytes = body.encode("utf-8")

response = self._client.object.get(
container=self._container, path=self._object_path, raise_for_status=v3io.dataplane.RaiseForStatus.never
)

self.assertEqual(404, response.status_code)

# put contents to some object
self._client.object.put(container=self._container, path=self._object_path, body=contents)
# put body to some object
self._client.object.put(container=self._container, path=self._object_path, body=body)

# get the object contents
# get the object body
response = self._client.object.get(container=self._container, path=self._object_path)
if not isinstance(response.body, str):
response.body = response.body.decode("utf-8")
self.assertEqual(response.body, contents)
self.assertEqual(response.body, body_bytes)

response = self._client.object.get(container=self._container, path=self._object_path, offset=0, num_bytes=10)
if not isinstance(response.body, str):
response.body = response.body.decode("utf-8")
self.assertEqual(response.body, contents[0:10])
self.assertEqual(response.body, body_bytes[0:10])

# get the head of the object
response = self._client.object.head(container=self._container, path=self._object_path)

self.assertIn(("Content-Length", str(len(contents))), response.headers.items())
self.assertIn(("Content-Length", str(len(body_bytes))), response.headers.items())

# get the head of the dir-object
response = self._client.object.head(container=self._container, path=self._object_dir)

self.assertIn(("Content-Length", str(0)), response.headers.items())
self.assertIn(("Content-Length", "0"), response.headers.items())

# delete the object
self._client.object.delete(container=self._container, path=self._object_path)
Expand Down
10 changes: 8 additions & 2 deletions v3io/dataplane/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,19 @@ def encode_get_object(container_name, access_key, kwargs):


def encode_put_object(container_name, access_key, kwargs):
headers = None
headers = {
"Content-Type": "application-octet-stream",
assaf758 marked this conversation as resolved.
Show resolved Hide resolved
}

# if the append flag is passed, add a range header
if kwargs["append"]:
headers = {"Range": "-1"}

return _encode("PUT", container_name, access_key, kwargs["path"], None, headers, kwargs["body"])
body = kwargs["body"]
if isinstance(body, str):
body = body.encode("utf-8")

return _encode("PUT", container_name, access_key, kwargs["path"], None, headers, body)
assaf758 marked this conversation as resolved.
Show resolved Hide resolved


def encode_delete_object(container_name, access_key, kwargs):
Expand Down
Loading