added a do_HEAD() function

This commit is contained in:
Mark McIntyre 2020-09-09 06:43:52 -04:00
parent 6ad3c2c2de
commit 4f60c76c86

View File

@ -11,9 +11,31 @@ _format = "%(asctime)-15s [%(levelname)-8s] %(lineno)d : %(funcName)s : %(messag
logging.basicConfig(format=_format, level=_level)
log = logging.getLogger()
# Version
version = "1.1.1"
class SimpleHandler(http.server.BaseHTTPRequestHandler):
def do_HEAD(self):
log.info(f"server version: {self.server_version}")
log.info(f"client address: {self.client_address}")
log.info(f"path: {self.path}")
log.info(f"headers: {self.headers}")
log.info(f"request version: {self.request_version}")
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
if self.path != '/':
message = f"Hello, {self.path[1:]} World! - {version}"
else:
message = "Hello, World! - {version}"
self.wfile.write(bytes(message, encoding='utf-8'))
return
def do_GET(self):
log.info(f"server version: {self.server_version}")
log.info(f"client address: {self.client_address}")