mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
record response content:
1, only record json if response content is in JSON foramt; 2, do not record bytes content; 3, omit text charactors greater than 1000.
This commit is contained in:
@@ -56,7 +56,6 @@ class HttpSession(requests.Session):
|
||||
"response_time_ms": "N/A",
|
||||
"elapsed_ms": "N/A",
|
||||
"encoding": None,
|
||||
"content": None,
|
||||
"content_type": ""
|
||||
}
|
||||
}
|
||||
@@ -139,14 +138,20 @@ class HttpSession(requests.Session):
|
||||
self.meta_data["response"]["headers"] = dict(response.headers)
|
||||
self.meta_data["response"]["cookies"] = response.cookies or {}
|
||||
self.meta_data["response"]["encoding"] = response.encoding
|
||||
self.meta_data["response"]["content"] = response.content
|
||||
self.meta_data["response"]["text"] = response.text
|
||||
self.meta_data["response"]["content_type"] = response.headers.get("Content-Type", "")
|
||||
|
||||
try:
|
||||
# try to only record json data
|
||||
self.meta_data["response"]["json"] = response.json()
|
||||
except ValueError:
|
||||
self.meta_data["response"]["json"] = None
|
||||
# only record at most 1000 text charactors
|
||||
resp_text = response.text
|
||||
resp_text_length = len(resp_text)
|
||||
if resp_text_length > 1000:
|
||||
resp_text = resp_text[0:1000] \
|
||||
+ " ... OMITTED {} CHARACTORS ...".format(resp_text_length-1000)
|
||||
|
||||
self.meta_data["response"]["text"] = resp_text
|
||||
|
||||
# get the length of the content, but if the argument stream is set to True, we take
|
||||
# the size from the content-length header, in order to not trigger fetching of the body
|
||||
|
||||
Reference in New Issue
Block a user