updated the formatting and added all the header info to the do_HEAD() call

This commit is contained in:
Mark McIntyre 2020-09-14 09:21:35 -04:00
parent 77592ad123
commit fd910e06e8

View File

@ -29,10 +29,22 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/html')
self.end_headers()
headers = "\n".join([f"{k}: {v}" for k, v in self.headers.items()])
if self.path != '/':
message = f"Hello, {self.path[1:]} World! - {version}"
uri = f"{self.path[1:]} "
else:
message = f"Hello, World! - {version}"
uri = ""
message = f"""Hello, {uri}World!
App version: {version}
Server version: {self.server_version}
Client address: {self.client_address}
Path: {self.path}
Headers:
{pprint.pformat(self.headers)}
Request version: {self.request_version}
"""
self.wfile.write(bytes(message, encoding='utf-8'))
return
@ -51,27 +63,19 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler):
headers = "<br/>".join([f"{k}: {v}" for k, v in self.headers.items()])
if self.path != '/':
message = f"""<html><body>
<h1>Hello, {self.path[1:]} World!</h1>
<p>App version: <b>{version}</b></p>
<p>Server version: <b>{self.server_version}</b></p>
<p>Client address: <b>{self.client_address}</b></p>
<p>Path: <b>{self.path}</b></p>
<p>Headers:</p> <p><code>{headers}</code></p>
<p>dir(headers) = {dir(self.headers)}</p>
<p>Request version: <b>{self.request_version}</b></p>
</body></html>"""
uri = f"{self.path[1:]} "
else:
message = f"""<html><body>
<h1>Hello, {self.path[1:]} World!</h1>
<p>App version: <b>{version}</b></p>
<p>Server version: <b>{self.server_version}</b></p>
<p>Client address: <b>{self.client_address}</b></p>
<p>Path: <b>{self.path}</b></p>
<p>Headers:</p> <p><code>{pprint.pformat(self.headers)}</code></p>
<p>dir(headers) = {dir(self.headers)}</p>
<p>Request version: <b>{self.request_version}</b></p>
</body></html>"""
uri = ""
message = f"""<html><body>
<h1>Hello, {uri}World!</h1>
<p>App version: <b>{version}</b></p>
<p>Server version: <b>{self.server_version}</b></p>
<p>Client address: <b>{self.client_address}</b></p>
<p>Path: <b>{self.path}</b></p>
<p>Headers:</p> <p><code>{pprint.pformat(self.headers)}</code></p>
<p>Request version: <b>{self.request_version}</b></p>
</body></html>"""
self.wfile.write(bytes(message, encoding='utf-8'))
return