示例#1
0
    def fetch10(self, s, uri):

        b = Buffer(1024)
        b.clear()
        b.write_bytes("GET %s HTTP/1.0\r\n" % uri)
        b.write_bytes("\r\n")
        b.flip()
        s.write(b)

        b.clear()
        s.read(b)
        b.flip()
        return b.read_bytes(b.remaining)
示例#2
0
    def fetch10(self, s, uri):

        b = Buffer(1024)
        b.clear()
        b.write_bytes("GET %s HTTP/1.0\r\n" % uri)
        b.write_bytes("\r\n")
        b.flip()
        s.write(b)
        
        b.clear()
        s.read(b)
        b.flip()
        return b.read_bytes(b.remaining)
示例#3
0
def handle(client_socket):
    buffer = Buffer(1024)
    client_socket.read(buffer) #read the request
    buffer.clear()
    buffer.write_bytes(
            "HTTP/1.0 200 OK\r\n"                     \
            "Content-Length: 13\r\n"                  \
            "Connection: close\r\n"                   \
            "\r\n"                                    \
            "Hello World!\n"
        )
    buffer.flip()
    client_socket.write(buffer)
    client_socket.close()
示例#4
0
 def testParserSpeed(self):
     N = 500000
     b = Buffer(1024)
     b.write_bytes("GET /bla.html?piet=blaat&jaap=aap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("\r\n")
     b.flip()
     with unittest.timer() as tmr:
         for i in range(N):
             p = _http.HTTPParser(b)
             p.parse()
             b.position = 0
     print tmr.sec(N)
示例#5
0
 def testParserSpeed(self):
     N = 500000
     b = Buffer(1024)
     b.write_bytes("GET /bla.html?piet=blaat&jaap=aap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("\r\n")
     b.flip()
     with unittest.timer() as tmr:
         for i in range(N):
             p = _http.HTTPParser(b)
             p.parse()
             b.position = 0
     print tmr.sec(N)
示例#6
0
 def testParser(self):
     b = Buffer(1024)
     b.write_bytes("POST /bla.html?piet=blaat&jaap=aap#blaataap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("Another-header: blaat: piet\r\n")
     b.write_bytes("Another-header: blaat: piet\r\n")
     b.write_bytes("Content-type: blaat/piet\r\n")
     b.write_bytes("\r\n")
     b.write_bytes("1234567890")
     b.flip()
     print b.limit, b.position
     p = _http.HTTPParser(b)
     print repr(p.environ)
     print 'isfin', repr(p.is_finished())
     print p.parse()
     print 'isfin', repr(p.is_finished())
     print b.limit, b.position
     print repr(p.environ)
     print p.parse()
示例#7
0
 def testParser(self):
     b = Buffer(1024)
     b.write_bytes(
         "POST /bla.html?piet=blaat&jaap=aap#blaataap HTTP/1.1\r\n")
     b.write_bytes("Content-length: 10\r\n")
     b.write_bytes("Another-header: blaat: piet\r\n")
     b.write_bytes("Another-header: blaat: piet\r\n")
     b.write_bytes("Content-type: blaat/piet\r\n")
     b.write_bytes("\r\n")
     b.write_bytes("1234567890")
     b.flip()
     print b.limit, b.position
     p = _http.HTTPParser(b)
     print repr(p.environ)
     print 'isfin', repr(p.is_finished())
     print p.parse()
     print 'isfin', repr(p.is_finished())
     print b.limit, b.position
     print repr(p.environ)
     print p.parse()