diff --git a/plugins/eddn.py b/plugins/eddn.py index 6275349f..dd8e6cab 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -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'} diff --git a/util/http.py b/util/http.py index 441ff386..8a8578b9 100644 --- a/util/http.py +++ b/util/http.py @@ -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'