Compress RPC responses

Closes #13235
This commit is contained in:
Cédric Krier
2024-05-04 18:43:27 +02:00
parent 0807b42e87
commit 5af12a226e
3 changed files with 19 additions and 6 deletions
+1
View File
@@ -1,3 +1,4 @@
* Compress RPC responses
* Change _changed_values and _save_values properties to method
* Add configuration for report convert command
* Use process pool to run cron
+9 -3
View File
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
import base64
import datetime
import gzip
import json
from decimal import Decimal
@@ -188,6 +189,11 @@ class JSONProtocol:
elif isinstance(data, Exception):
return InternalServerError(data)
response = data
return Response(json.dumps(
response, cls=JSONEncoder, separators=(',', ':')),
content_type='application/json')
headers = {}
data = json.dumps(
response, cls=JSONEncoder, separators=(',', ':'))
if len(data) >= 1400 and 'gzip' in request.accept_encodings:
data = gzip.compress(data.encode('utf-8'), compresslevel=1)
headers['Content-Encoding'] = 'gzip'
return Response(
data, content_type='application/json', headers=headers)
+9 -3
View File
@@ -1,6 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
import gzip
import logging
import xmlrpc.client as client
# convert decimal to float before marshalling:
@@ -166,9 +167,14 @@ class XMLProtocol:
data = client.Fault(255, str(data))
else:
data = (data,)
return Response(client.dumps(
data, methodresponse=True, allow_none=True),
content_type='text/xml')
headers = {}
data = client.dumps(
data, methodresponse=True, allow_none=True)
if len(data) >= 1400 and 'gzip' in request.accept_encodings:
data = gzip.compress(data.encode('utf-8'), compresslevel=1)
headers['Content-Encoding'] = 'gzip'
return Response(
data, content_type='text/xml', headers=headers)
else:
if isinstance(data, UserWarning):
return Conflict(data)