def inject_html(request, response, data, summary_data):
try:
body_closing_index = response.content.rindex(b'</body>')
except ValueError:
return
content = ' | '.join(
'%s=%s' % (key, round(value, 3) if isinstance(value, float) else value)
for (key, value)
in sorted(summary_data.items())
)
ns = 'cv_%s' % get_random_string()
html = """<style>{style}</style><div id="{ns}">{content}</div>""".format(
ns=ns,
content=content,
style=STYLE.replace('#cv', '#' + ns),
)
script = generate_console_script(data, with_stacks=bool(request.GET.get('_cavalry_stacks')))
html += "<script>{script}</script>".format(script='\n'.join(script))
response.content = (
response.content[:body_closing_index] +
html.encode('utf-8') +
response.content[body_closing_index:]
)
if 'content-length' in response:
response['content-length'] = len(response.content)
评论列表
文章目录