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