Skip to content

Commit

Permalink
fix: do not use magic library to discover content type
Browse files Browse the repository at this point in the history
  • Loading branch information
plankthom committed Feb 6, 2024
1 parent 9a79d4c commit 49ffa3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/waylay/sdk/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
3 changes: 1 addition & 2 deletions test/unit/api/__snapshots__/api_client_test.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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..',
),
]),
Expand Down
1 change: 0 additions & 1 deletion test/unit/api/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 49ffa3a

Please sign in to comment.