from http.server import BaseHTTPRequestHandler, HTTPServer
html = """
Lynx Form Test
"""
class Handler(BaseHTTPRequestHandler):
def __init__(self, request, client_address, server):
self.msg = "Expected POST request. Actual method was {}."
super().__init__(request, client_address, server)
def respond(self, status, content_type, content):
self.send_response(status)
self.send_header("Content-Type", content_type)
self.end_headers()
self.wfile.write(bytes(content, "utf-8"))
def do_GET(self):
if self.path == "/submit":
self.respond(200, "text/plain", self.msg.format("GET"))
return
self.respond(200, "text/html", html)
def do_POST(self):
if self.path == "/submit":
self.respond(200, "text/plain", self.msg.format("POST"))
return
self.respond(405, "text/plain", "Method Not Allowed\n")
srv = HTTPServer(("", 8000), Handler)
print("Serving HTTP on port 8000 ...")
srv.serve_forever()