|
@@ -1,5 +1,7 @@
|
|
|
import simplejson as json
|
|
|
from django.shortcuts import HttpResponse
|
|
|
+import gzip
|
|
|
+from io import BytesIO
|
|
|
|
|
|
|
|
|
class ResponseObject(object):
|
|
@@ -306,4 +308,14 @@ class ResponseObject(object):
|
|
|
if res is None:
|
|
|
res = {}
|
|
|
result = self.formal(code, res)
|
|
|
- return HttpResponse(result)
|
|
|
+ # 将数据压缩
|
|
|
+ buffer = BytesIO()
|
|
|
+ with gzip.GzipFile(fileobj=buffer, mode='wb') as f:
|
|
|
+ f.write(result.encode('utf-8'))
|
|
|
+
|
|
|
+ compressed_content = buffer.getvalue()
|
|
|
+
|
|
|
+ response = HttpResponse(compressed_content, content_type='application/json')
|
|
|
+ response['Content-Encoding'] = 'gzip'
|
|
|
+ response['Content-Length'] = str(len(compressed_content))
|
|
|
+ return response
|