from http.server import BaseHTTPRequestHandler, HTTPServer

class handler(BaseHTTPRequestHandler):
    names = []
    def _set_response(self, name):
        if name not in self.names:
            self.names.append(name)
            self.send_response(200)
        else:
            self.send_response(403)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_POST(self):
        content_length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(content_length) 
        name = post_data.decode('utf-8')
        print("Client List: ", self.names)
        print("Body:", name)
        self._set_response(name)
    

def run(server_class=HTTPServer, handler_class=handler, port=8080):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print('Starting httpd...\n')
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print('Stopping httpd...\n')
    
run()