from whoops import ioloop, async_server

class EchoServer(async_server.AsyncServer):

    def on_connection(self, conn):
        data = conn.read()
        print(data)
        conn.write(b"HTTP/1.1 200 OK\r\nServer: myhttpd/0.1.0\r\nContent-Type: text/html\r\nContent-Length: 20\r\n\r\n<html>Hello</html>\r\n")

if __name__ == "__main__":
    EchoServer(ioloop.IOLoop.instance(num_backends=1000),
    ('127.0.0.1', 8888)).listen()

@@ -1,8 +1,70 @@
+from http.client import parse_headers%0Afrom io import BytesIO%0A%0A
 from who
@@ -100,18 +100,19 @@
 er%0A%0A
+%0A
 class 
-Echo
+Http
 Serv
@@ -154,155 +154,834 @@
 def 
-on_connection(self, conn):%0A        data = conn.read()%0A        print(data)%0A        conn.write(b%22HTTP/1.1 200 OK%5Cr%5CnServer: myhttpd/0.1.0%5Cr%5Cn
+__init__(self, ioloop, address):%0A        super(HttpServer, self).__init__(ioloop, address)%0A%0A        self.rbufsize = -1%0A        self.wbufsize = 0%0A        self.rfile = None%0A        self.wfile = None%0A        self.connection = None%0A        self.raw_requestline = None%0A        self.headers = None%0A        self._headers_buffer = %5B%5D%0A%0A        %0A    def on_connection(self, conn):%0A        self.connection = conn%0A        self.parse_request()%0A        self.do_response()%0A%0A    def parse_request(self):%0A        data = self.connection.read()%0A        self.rfile = BytesIO(data)%0A        self.raw_requestline = self.rfile.readline(65537)%0A        self.header = parse_headers(self.rfile)%0A%0A    def do_response(self):%0A        body = %22%3Chtml%3E%3Cbody%3E%3Ch2%3EHello Whoops%3C/h2%3E%3C/body%3E%3C/html%3E%22%0A        self.send_response(200)%0A        self.send_header(%22
 Content-
 Type
@@ -980,14 +980,16 @@
 ent-
-Type: 
+type%22, %22
 text
@@ -997,61 +997,894 @@
 html
-%5Cr%5CnContent-Length: 20%5Cr%5Cn%5Cr%5Cn%3Chtml%3EHello%3C/html%3E%5Cr%5Cn%22
+%22)%0A        self.send_header(%22Content-Length%22, len(body))%0A        self.end_headers()%0A        self.send_body(body)%0A%0A    def send_response(self, code, message=None):%0A        self._headers_buffer.append(%0A            (%22%25s %25d %25s%5Cr%5Cn%22 %25 ('HTTP/1.1', code, message)).encode('latin-1', 'strict'))%0A        self.send_header('Server', 'whoops/0.1')%0A%0A    def send_header(self, key, value):%0A        self._headers_buffer.append(%0A            (%22%25s: %25s%5Cr%5Cn%22 %25 (key, value)).encode('latin-1', 'strict'))%0A%0A    def end_headers(self):%0A        self._headers_buffer.append(b%22%5Cr%5Cn%22)%0A        self.flush_headers()%0A%0A    def flush_headers(self):%0A        self.send(b''.join(self._headers_buffer))%0A        self._headers_buffer = %5B%5D%0A%0A    def send_body(self, body):%0A        self.send(body.encode('latin-1'))%0A%0A    def send(self, msg, body=None):%0A        if body:%0A            msg += body%0A        self.connection.write(msg
 )%0A%0Ai
@@ -1917,12 +1917,12 @@
     
-Echo
+Http
 Serv
@@ -1967,16 +1967,27 @@
 =1000),%0A
+           
     ('12

improve http server example