import http.server import urllib.parse class HTTPRequestHandler(http.server.BaseHTTPRequestHandler): server_version = 'Buranun/0.0' protocol_version = 'HTTP/1.1' def __send_plaintext(self, string): if string[-1:] != '\n': string += '\n' encoded = string.encode('utf-8') length = len(encoded) self.send_response(200) self.send_header('Content-Type', 'text/plain; charset=utf-8') self.send_header('Content-Length', length) self.end_headers() self.wfile.write(encoded) def do_GET(self): path = urllib.parse.unquote(self.path) self.__send_plaintext(path) def main(): httpd = http.server.HTTPServer(('', 8000), HTTPRequestHandler) httpd.serve_forever() if __name__ == '__main__': main()