gns3-docker-appliances/basic_server/server.py

25 lines
598 B
Python

from http.server import BaseHTTPRequestHandler, HTTPServer
import os
message = "Hello, World! Here is simple HTTP response..."
if "MESSAGE" in os.environ:
message = os.environ["MESSAGE"]
PORT = 80
print(f"Will listen on port {PORT}")
class handler(BaseHTTPRequestHandler):
def do_GET(self):
global message
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
message = f"{message}\n"
self.wfile.write(bytes(message, "utf8"))
with HTTPServer(('', PORT), handler) as server:
server.serve_forever()