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

Commit

Permalink
add decode for res content
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidaya0 committed Dec 24, 2021
1 parent f87a247 commit db5ca88
Show file tree
Hide file tree
Showing 2 changed files with 737 additions and 3 deletions.
27 changes: 25 additions & 2 deletions apiserver/report/handler/saas_method_pool_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from apiserver import utils
from apiserver.report.handler.report_handler_interface import IReportHandler
from apiserver.report.report_handler_factory import ReportHandler

import gzip
logger = logging.getLogger('dongtai.openapi')


Expand Down Expand Up @@ -151,7 +151,8 @@ def save_method_call(self, pool_sign, current_version_agents):
query_params=self.http_query_string,
http_protocol=self.http_protocol)
method_pool.res_header = utils.base64_decode(self.http_res_header)
method_pool.res_body = self.http_res_body
method_pool.res_body = decode_content(
self.http_res_body, get_content_encoding(self.http_req_header))
method_pool.uri_sha1 = self.sha1(self.http_uri)
method_pool.save(update_fields=[
'update_time',
Expand Down Expand Up @@ -225,3 +226,25 @@ def sha1(raw):
h = sha1()
h.update(raw.encode('utf-8'))
return h.hexdigest()


def decode_content(body, content_type):
if content_type == 'gzip':
try:
return gzip.decompress(bytes(body, encoding='utf-8'))
except:
logger.error('not gzip type but using gzip as content_encoding')
return body
return body


def get_content_encoding(header):
headers = SaasMethodPoolHandler.parse_headers(header)
for header in headers:
try:
k, v = header.strip().split(':')
if k.lower() == 'content-encoding':
return v
except:
pass
return ''
Loading

0 comments on commit db5ca88

Please sign in to comment.