fix html report display response content

This commit is contained in:
debugtalk
2018-11-26 14:36:07 +08:00
parent 19e8130e6a
commit d08642f812
2 changed files with 23 additions and 15 deletions
+8 -2
View File
@@ -138,10 +138,16 @@ 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_type"] = response.headers.get("Content-Type", "")
content_type = response.headers.get("Content-Type", "")
self.meta_data["response"]["content_type"] = content_type
if "image" in content_type:
# response is image type, record bytes content only
self.meta_data["response"]["content"] = response.content
else:
try:
# try to only record json data
# try to record json data
self.meta_data["response"]["json"] = response.json()
except ValueError:
# only record at most 1000 text charactors
+4 -2
View File
@@ -272,7 +272,7 @@
<div style="overflow: auto">
<table>
{% for key, value in record.meta_data.response.items() %}
{% if key in ["text", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type"] %}
{% if key in ["elapsed_ms", "response_time_ms", "content_size", "content_type"] %}
{% continue %}
{% endif %}
<tr>
@@ -288,8 +288,10 @@
{% if "image" in record.meta_data.response.content_type %}
<img src="{{ record.meta_data.response.content }}" />
{% else %}
<pre>{{ record.meta_data.response.text | e }}</pre>
{{ value }}
{% endif %}
{% elif key == "text" %}
<pre>{{ record.meta_data.response.text | e }}</pre>
{% else %}
{{ value }}
{% endif %}