From 49ffa3ac91dffecc5b263673f74ab85ff4c28e20 Mon Sep 17 00:00:00 2001 From: Thomas De Smedt Date: Tue, 6 Feb 2024 17:39:42 +0100 Subject: [PATCH] fix: do not use `magic` library to discover content type --- src/waylay/sdk/api/rest.py | 10 +++++----- test/unit/api/__snapshots__/api_client_test.ambr | 3 +-- test/unit/api/api_client_test.py | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/waylay/sdk/api/rest.py b/src/waylay/sdk/api/rest.py index e120ee4..5a677f4 100644 --- a/src/waylay/sdk/api/rest.py +++ b/src/waylay/sdk/api/rest.py @@ -82,11 +82,11 @@ async def request( if isinstance(body, BufferedReader): body = body.read() if not headers.get('content-type'): - try: - import magic - mime_type = magic.from_buffer(body) - except BaseException: - mime_type = 'application/octet-stream' + # try: + # import magic + # mime_type = magic.from_buffer(body) + # except BaseException: + mime_type = 'application/octet-stream' kwargs['headers'].update({'content-type': mime_type}) kwargs.update({'content': body}) elif content_type and content_type != 'application/json': diff --git a/test/unit/api/__snapshots__/api_client_test.ambr b/test/unit/api/__snapshots__/api_client_test.ambr index 9a495af..5534f49 100644 --- a/test/unit/api/__snapshots__/api_client_test.ambr +++ b/test/unit/api/__snapshots__/api_client_test.ambr @@ -443,7 +443,6 @@ 'body': b'..some binary content..', 'files': None, 'header_params': dict({ - 'Content-Type': 'application/octet-stream', 'User-Agent': 'waylay-sdk/python/0.0.0', }), 'method': 'POST', @@ -458,7 +457,7 @@ ]), list([ tuple( - Headers([('host', 'api-example.io'), ('accept', '*/*'), ('accept-encoding', 'gzip, deflate'), ('connection', 'keep-alive'), ('content-type', 'application/octet-stream'), ('user-agent', 'waylay-sdk/python/0.0.0'), ('content-type', 'application/octet-stream'), ('content-length', '23'), ('authorization', '[secure]')]), + Headers({'host': 'api-example.io', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive', 'user-agent': 'waylay-sdk/python/0.0.0', 'content-type': 'application/octet-stream', 'content-length': '23', 'authorization': '[secure]'}), b'..some binary content..', ), ]), diff --git a/test/unit/api/api_client_test.py b/test/unit/api/api_client_test.py index 771cd68..c42b7f3 100644 --- a/test/unit/api/api_client_test.py +++ b/test/unit/api/api_client_test.py @@ -91,7 +91,6 @@ def waylay_api_client(waylay_config: WaylayConfig) -> ApiClient: 'method': 'POST', 'resource_path': '/service/v1/bar/foo', 'body': b'..some binary content..', - 'header_params': {'Content-Type': 'application/octet-stream'}, }, 'form': { 'method': 'POST',