""" Handle the initiator navigation request and attach the received client info
to the returned page.
"""
import textwrap
html_template = """
echo client hints on prerendering page
"""
def translate_to_js(val: bool) -> str:
if isinstance(val, bool):
return "true" if val else "false"
return ""
def main(request, response):
response.status = 200
# Insert the received hints into script.
content = html_template % (
textwrap.dedent(
f"""
const server_received_bitness =
{translate_to_js(b"sec-ch-ua-bitness" in request.headers)};
const server_received_full_version_list =
{translate_to_js(b"sec-ch-ua-full-version-list" in
request.headers)};
"""
)
)
response.content = content.encode("utf-8")