more formatting and information changes to the python-web-server

This commit is contained in:
Mark McIntyre 2020-09-11 12:09:49 -04:00
parent d5f4559afc
commit 77592ad123

View File

@ -4,6 +4,7 @@ import argparse
import http.server
import socketserver
import logging
import pprint
# setting up logging for this script
_level = logging.INFO
@ -47,10 +48,30 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/html')
self.end_headers()
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>{version}</p></body></html>"
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>"""
else:
message = f"<html><body><h1>Hello, World!</h1><p>{version}</p></body></html>"
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>"""
self.wfile.write(bytes(message, encoding='utf-8'))
return