1#!/usr/bin/env python3 2 3import socket 4from http.server import HTTPServer, BaseHTTPRequestHandler 5 6PORT = 8000 7 8class HTTPServerV6(HTTPServer): 9 address_family = socket.AF_INET6 10 11class RequestHandler(BaseHTTPRequestHandler): 12 length = 0 13 14 def _set_headers(self): 15 self.send_response(200) 16 self.send_header('Content-Type', 'text/html') 17 self.send_header('Content-Length', str(self.length)) 18 self.end_headers() 19 20 def do_POST(self): 21 payload = "<html><p>Done</p></html>" 22 self.length = len(payload) 23 self._set_headers() 24 self.wfile.write(payload.encode()) 25 26 def do_GET(self): 27 payload = "<html><p>Done</p></html>" 28 self.length = len(payload) 29 self._set_headers() 30 self.wfile.write(payload.encode()) 31 32def main(): 33 httpd = HTTPServerV6(("", PORT), RequestHandler) 34 print("Serving at port", PORT) 35 httpd.serve_forever() 36 37if __name__ == '__main__': 38 main() 39