Skip to content

Commit

Permalink
添加请求数据到响应元数据 (#164)
Browse files Browse the repository at this point in the history
* 添加请求数据到响应元数据

* ruff format
  • Loading branch information
wu-clan authored Mar 11, 2024
1 parent d8a1feb commit 0e6b019
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def init_response_metadata(self) -> dict:
'stat': {
'execute_time': None,
},
'request': None,
}
return response_metadata

Expand Down Expand Up @@ -201,14 +202,16 @@ def send_request(
'params': parsed_data['params'],
'headers': parsed_data['headers'],
'cookies': parsed_data['cookies'],
'data': parsed_data['body'],
'body': parsed_data['body'],
'files': parsed_data['files'],
}
if parsed_data['body_type'] == BodyType.JSON or parsed_data['body_type'] == BodyType.GraphQL:
request_data_parsed.update({'json': request_data_parsed.pop('data')})
request_data_parsed.update({'json': request_data_parsed.pop('body')})
elif parsed_data['body_type'] == BodyType.binary:
if request_engin == EnginType.httpx:
request_data_parsed.update({'content': request_data_parsed.pop('data')})
request_data_parsed.update({'content': request_data_parsed.pop('body')})
else:
request_data_parsed.update({'data': request_data_parsed.pop('body')})

# 发送请求
response_data = self.init_response_metadata
Expand All @@ -234,6 +237,7 @@ def send_request(
response_data['json'] = json_data
response_data['content'] = response.content.decode('utf-8')
response_data['text'] = response.text
response_data['request'] = request_data_parsed

# 日志记录响应数据
teardown = parsed_data['teardown']
Expand Down

0 comments on commit 0e6b019

Please sign in to comment.