diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index d718ade873..8816394b89 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -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 diff --git a/trytond/trytond/protocols/jsonrpc.py b/trytond/trytond/protocols/jsonrpc.py index db854c81ac..53bdb3cdef 100644 --- a/trytond/trytond/protocols/jsonrpc.py +++ b/trytond/trytond/protocols/jsonrpc.py @@ -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) diff --git a/trytond/trytond/protocols/xmlrpc.py b/trytond/trytond/protocols/xmlrpc.py index 4ed0e8dc3d..dc1ff0fb13 100644 --- a/trytond/trytond/protocols/xmlrpc.py +++ b/trytond/trytond/protocols/xmlrpc.py @@ -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)