mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: log request/response headers and body with indent
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
- feat: make testsuite and run testsuite
|
- feat: make testsuite and run testsuite
|
||||||
- feat: testcase/testsuite config support getting variables by function
|
- feat: testcase/testsuite config support getting variables by function
|
||||||
- feat: har2case with request cookies
|
- feat: har2case with request cookies
|
||||||
|
- feat: log request/response headers and body with indent
|
||||||
|
|
||||||
**Fixed**
|
**Fixed**
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -32,12 +33,19 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData:
|
|||||||
def log_print(req_or_resp, r_type):
|
def log_print(req_or_resp, r_type):
|
||||||
msg = f"\n================== {r_type} details ==================\n"
|
msg = f"\n================== {r_type} details ==================\n"
|
||||||
for key, value in req_or_resp.dict().items():
|
for key, value in req_or_resp.dict().items():
|
||||||
msg += "{:<16} : {}\n".format(key, repr(value))
|
if isinstance(value, dict):
|
||||||
|
value = json.dumps(value, indent=4)
|
||||||
|
|
||||||
|
msg += "{:<8} : {}\n".format(key, value)
|
||||||
logger.debug(msg)
|
logger.debug(msg)
|
||||||
|
|
||||||
# record actual request info
|
# record actual request info
|
||||||
request_headers = dict(resp_obj.request.headers)
|
request_headers = dict(resp_obj.request.headers)
|
||||||
request_body = resp_obj.request.body
|
request_body = resp_obj.request.body
|
||||||
|
try:
|
||||||
|
request_body = json.loads(request_body)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
pass
|
||||||
|
|
||||||
if request_body:
|
if request_body:
|
||||||
request_content_type = lower_dict_keys(request_headers).get("content-type")
|
request_content_type = lower_dict_keys(request_headers).get("content-type")
|
||||||
|
|||||||
Reference in New Issue
Block a user