mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-08 03:12:33 +03:00
always compress eddn data, comment rationale
This commit is contained in:
parent
2b8fe57bc7
commit
73f45e37cd
@ -219,7 +219,16 @@ class EDDN:
|
|||||||
('message', msg['message']),
|
('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
|
headers: None | dict[str, str] = None
|
||||||
if compressed:
|
if compressed:
|
||||||
headers = {'Content-Encoding': 'gzip'}
|
headers = {'Content-Encoding': 'gzip'}
|
||||||
|
@ -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.
|
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 data: The data to compress
|
||||||
:param max_size: The max size of data, in bytes, defaults to 512
|
: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'
|
:param encoding: The encoding to use if data is a str, defaults to 'utf-8'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user