import sys if sys.argv[1] == 'client': from http.client import HTTPConnection conn = HTTPConnection('localhost', 8080) conn.putrequest('GET', '/') conn.endheaders() conn.send(b'\r\n\r\n') response = conn.getresponse() print(response.headers.defects) conn.close() else: from http.server import BaseHTTPRequestHandler, HTTPServer class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-Type', 'multipart/mixed; boundary=boundary') self.end_headers() self.wfile.write(b'--boundary\r\nContent-Type:text/plain\r\n\r\nhello\r\n\r\n--boundary--') return server = HTTPServer(('localhost', 8080), Handler) server.serve_forever()