Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit db5ca88

Browse files
committed
add decode for res content
1 parent f87a247 commit db5ca88

File tree

2 files changed

+737
-3
lines changed

2 files changed

+737
-3
lines changed

apiserver/report/handler/saas_method_pool_handler.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from apiserver import utils
2020
from apiserver.report.handler.report_handler_interface import IReportHandler
2121
from apiserver.report.report_handler_factory import ReportHandler
22-
22+
import gzip
2323
logger = logging.getLogger('dongtai.openapi')
2424

2525

@@ -151,7 +151,8 @@ def save_method_call(self, pool_sign, current_version_agents):
151151
query_params=self.http_query_string,
152152
http_protocol=self.http_protocol)
153153
method_pool.res_header = utils.base64_decode(self.http_res_header)
154-
method_pool.res_body = self.http_res_body
154+
method_pool.res_body = decode_content(
155+
self.http_res_body, get_content_encoding(self.http_req_header))
155156
method_pool.uri_sha1 = self.sha1(self.http_uri)
156157
method_pool.save(update_fields=[
157158
'update_time',
@@ -225,3 +226,25 @@ def sha1(raw):
225226
h = sha1()
226227
h.update(raw.encode('utf-8'))
227228
return h.hexdigest()
229+
230+
231+
def decode_content(body, content_type):
232+
if content_type == 'gzip':
233+
try:
234+
return gzip.decompress(bytes(body, encoding='utf-8'))
235+
except:
236+
logger.error('not gzip type but using gzip as content_encoding')
237+
return body
238+
return body
239+
240+
241+
def get_content_encoding(header):
242+
headers = SaasMethodPoolHandler.parse_headers(header)
243+
for header in headers:
244+
try:
245+
k, v = header.strip().split(':')
246+
if k.lower() == 'content-encoding':
247+
return v
248+
except:
249+
pass
250+
return ''

0 commit comments

Comments
 (0)