always compress eddn data, comment rationale

This commit is contained in:
A_D committed 2022-01-26 18:58:32 +02:00
1 parent 2b8fe57bc7
commit 73f45e37cd
2 files changed
+13 -1

No files matched your search

+10 -1
View File
@@ -219,7 +219,16 @@ class EDDN:
('message', msg['message']),
])
encoded, compressed = http.gzip(json.dumps(to_send))
# About the smallest request is going to be (newlines added for brevity):
# {"$schemaRef":"https://eddn.edcd.io/schemas/shipyard/2","header":{"softwareName":"E:D Market
# Connector Windows","softwareVersion":"5.3.0-beta4extra","uploaderID":"abcdefghijklm"},"messa
# ge":{"systemName":"delphi","stationName":"The Oracle","marketID":128782803,"timestamp":"xxxx
# -xx-xxTxx:xx:xxZ","ships":[]}}
#
# Which comes to about around 307 bytes. Lets play it safe and make our minimum 0 bytes.
# Which compresses everything
encoded, compressed = http.gzip(json.dumps(to_send, separators=(',', ':')), max_size=0)
headers: None | dict[str, str] = None
if compressed:
headers = {'Content-Encoding': 'gzip'}
+3
View File
@@ -10,6 +10,9 @@ def gzip(data: str | bytes, max_size: int = 512, encoding='utf-8') -> tuple[byte
"""
Compress the given data if the max size is greater than specified.
The default was chosen somewhat arbitrarily, see eddn.py for some more careful
work towards keeping the data almost always compressed
:param data: The data to compress
:param max_size: The max size of data, in bytes, defaults to 512
:param encoding: The encoding to use if data is a str, defaults to 'utf-8'